Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Embedding F-Script into Cocoa Applications
Subject:   Re: Eg.2, passing and retrieving
Date:   2002-08-07 10:22:51
From:   pmougin
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:



NSArray *airplanes

.

.

.



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)

[selectedAirplanes addObject:currentAirplane];

}





> 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.





Phil
Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • thanks
    2002-08-08 21:55:50  psheldon [View]

    Reminds me of a long ago memory of APL. Pretty good memory when I am exhausted from working out a digital laplacian version of Mike Beam's column.

    Need to figure out how to pencil around an F-Script sentence like :
    "[:a| a at:a location = 'CHICAGO' & (a capacity >=200)]"

    Also, might like to know if at: was short for attribute or where to go look it up, eg. examples on how to navigate your pdf book on F-Script. Maybe further columns will get up my nerve to navigate or I shall simply read the book when I get enough confidence.

    • thanks
      2002-08-09 09:46:33  pmougin [View]

      You’re right; F-Script is heavily inspired by APL. The "at:" method with an array of boolean argument implements the APL compression functionality.


      Note that at: is not short for "attribute". It’s similar to the NSArray “objectAtIndex:” method, just more general. For more on this method, look in the F-Script guide (http://www.fscript.org/download/FScriptGuide.pdf) at section 17.


      And, yes, in order to understand how the array expressions work in F-Script, you should definitely read the guide.


      Questions are welcome on the F-Script mailing list or directly to me.


      Phil