||Embedding F-Script into Cocoa Applications|
|Subject:||Re: Eg.2, passing and retrieving|
Response to: Eg.2, passing and retrieving
> So, I believe, this translates into obj c-code:
> [a at: [a location]='CHICAGO" & [a capacity] >= 200]
Not exactly. F-Script is an array language that let you manipulates arrays as a whole, taking care of iterating though the arrays’ elements automatically. This is not the case in Objective-C, where you have to explicitly code your loops.
In this particular example, the equivalent Objective-C code would looks like:
int i, nb;
NSArray *selectedAirplanes = [NSMutableArray array];
for (i=0, nb=[airplanes count]; i < nb; i++)
Airplane *currentAirplane = [airplanes objectAtIndex:i];
if ([currentAirplane location] isEqualToString:@"CHICAGO"] && [currentAirplane capacity] >= 200)
> Does this mean return a if true and nil if not true?
No. In the example, "a" is an array of Airplanes. And the argument passed to the "at:" method is an array of booleans, with the same number of elements than in the array "a". The result will be an array of Airplaines where only the elements in "a" that correspond to a Boolean with a value of true in the bollean array will be selected.
2002-08-08 21:55:50 psheldon [View]
2002-08-09 09:46:33 pmougin [View]