F-Script is an open-source interactive and scripting environment for Cocoa. See the project home at http://www.fscript.org.
print method to the NSObject class:
NSObject
{
- (void)print
{
stdout print:self description
}
}
See Creating Cocoa Classes with F-Script for more information.
at: (equivalent of objectForKey:)at:put: (equivalent of setObject:forKey:)printString method now invokes debugDescrition, when available, instead of description. The printString method is used by the F-Script console to display textual representations of objects.sizeWithWidth:height: defined in the FSNSValue category can now be passed negative numbers as arguments.objectPointer and objectPointer: of class FSPointer have been modified to use the NSAllocateCollectable function, with the NSScannedOption option, instead of malloc. This ensure that, in GC mode, the object(s) pointers stored in the memory zone represented by an FSObjectPointer are considered by the garbage collector as strong references, thus ensuring correct semantic for these methods.+(FSGenericPointer *)allocateCollectable:(NSUInteger)size options:(NSUInteger)options
is now available on class FSPointer. This method allocates a collectable memory zone with the NSAllocateCollectable function, then creates and returns an FSGenericPointer instance pointing to this zone, or nil if the memory cannot be allocated. If you want to pass 0 as option (which means that the memory zone is not scanned for pointers by the garbage collector), you might prefer to invoke the shorter convenience method, +(FSGenericPointer *)allocateCollectable:(NSUInteger)size.iTunes := SBApplication applicationWithBundleIdentifier:'com.apple.iTunes'iTunes currentTrack namemalloc_size() function to determine the size of the memory block to display. Thus, we might display memory contents that extend past the end of the memory block actually requested by the application at allocation time. In this case, some items at the end of the displayed content will just be the random values that happen to be there in memory.-> method, provided by the FSNSObject category, creates associations objects (e.g. myKey -> myValue). Association are typicaly used to define dictionary entries (see below).#{key1 -> value1, key2 -> value2}. This creates an NSMutableDictionary.16r; e.g., 16rFF5A==, nil now supports the ~~ message. With it, you can test if an object is not nil. So, instead of:(myObject == nil) notmyObject ~~ nilat:, at:put: and removeAt:. These methods perform either indexing or compression depending on the content of the first argument. F-Script 2 introduces dedicated methods for compression. These methods are: where:, where:put: and removeWhere:. You should use them instead of the at... methods. Compressing using the at... methods is, of course, still supported for backward compatibility, but this usage is now deprecated.inspect method has been added to the FSNSArray, FSNSDictionary and FSNSSet categories.stdin, stdout and stderr, give access to the standard IO streams. stdout and stderr provide a method for outputting a string: -(void) print:(NSString *)string. For example:stdout print:'hello world'log: method provided by the sys object, as the sys object is not available when developing F-Script classes.do: has been added to the FSNSArray category (a category of NSArray). The argument is a block with one argument. For each element of the receiver, the block is evaluated with the element as the parameter. The operation is evaluated with each element of the receiver in indexed order starting with element at index 0. The folowing example prints each element of an array of strings on the standard output:
{'one', 'two', 'three'} do:[:each| stdout print:each]
= and ~=) are provided for all objects. They are implemented in a category of NSObject, and rely on the standard Cocoa isEqual: method to determine equality.= and ~= are no longer provided at the NSObject level. The standard NSObject method for testing objects equality in Cocoa is isEqual:, and you can use it with F-Script too.= and ~= are no longer provided by default for all objects, they are implemented for a number of objects, such as NSString, NSNumber, NSDate, NSValue, FSBoolean... This covers the vast majority of current and desirable usage and you are also encouraged to implement them for your own classes if that make sense.= or ~= messages to objects that relied on the default implementation provided by the NSObject category in F-Script 1.x. In such cases, all will work as usual and F-Script will log a warning suggesting you change your code to use isEqual:.MaintainFScript1EqualityOperatorsSemantics user default, on an per application basis. For instance, to turn it off for the F-Script application, type the following in the Mac OS X terminal:defaults write org.fscript.fscriptapp MaintainFScript1EqualityOperatorsSemantics NOdefaults write org.fscript.fscriptapp MaintainFScript1EqualityOperatorsSemantics YES
NSString <-> char * mapping has been removed (i.e. the mapCharPointerToNSString user default is no longer effective).Array has been renamed FSArrayBlock has been renamed FSBlockNumber has been renamed FSNumberSystem has been renamed FSSystemSystem) are still present for backward compatibility, but their usage is deprecated. Note that if you have defined categories or subclasses for these classes, you must port them to the new classes.
JGType has been removed.enableJava has been removed from the FSSystem class.throw, introduced in F-Script 1.3.1, is now deprecated. Since Cocoa now specifies that exceptions should be represented by NSException objects, this method is no longer needed (NSException already provides raise... methods).clone method is now deprecated. With the advent of garbage collection, this convenience method is less useful.log:, loadSpace, loadSpace:, saveSpace, saveSpace:.vend: (FSNSObject) and connect (FSNSString) are deprecated.clear and clear: methods, provided by the System class, let you remove (i.e., undefine) variables from your workspace. The clear method removes all user-defined variables. The clear: method lets you specify the name of the variable you want to remove. Example:
> x := 2. y := 4.
> {x, y}
{2, 4}
> sys clear:'y' "Remove the y variable from the workspace"
> y
error: undefined identifier "y"
> sys clear "Remove all user-defined variables from the workspace"
> x
error: undefined identifier "x"
{x,y} := {2,4}{x,y} := {y,x}{ and }, separated by commas).arcCosh computes the principle value of the inverse hyperbolic cosine of the receiver.arcSinh computes the inverse hyperbolic sine of the receiver.arcTanh computes the inverse hyperbolic tangent of the receiver.erf computes the error function of the receiver.erfc computes the complementary error function of the receiver.log method that could lead to incorrect evaluation of logarithms for arrays of numbers has been fixed. You are advised to upgrade.anEmployee is a managed object with a salary property, you can write:anEmployee setSalary:2000anEmployee setValue:2000 forKey:'salary'throw method has been added to FSNSObject, a category of NSObject. Example:
['hello' throw] onException:[:exception| sys log:exception]
@try
{
@throw @"hello";
}
catch (id exception)
{
NSLog(exception);
}
executeWithArguments: method has been added to the Block class. This method executes a block and returns an FSInterpreterResult object describing the outcome of the execution. This is primarily useful when you want to use F-Script from Objective-C code. The FSinterpreterResult object lets you access either the result of the execution or a precise description of the error that resulted from the execution. Example:
// Create an F-Script block Block *myBlock = [@"[:a :b| a/b]" asBlock]; // Prepare the arguments for block execution NSArray *arguments = [NSArray arrayWithObjects:[NSNumber numberWithInt:10], [NSNumber numberWithInt:0], nil]; // Execute the block and get back an FSInterpreterResult instance FSInterpreterResult *interpreterResult = [myBlock executeWithArguments:arguments]; // Deal with the result of the execution if ([interpreterResult isOK]) NSLog(@"Execution OK. Result = %@", [interpreterResult result]); else NSLog([interpreterResult errorMessage]);When executed, this code will log "error: division by zero".

enclose and enclose: methods in the FSNSObject category.replication: and rotation: methods in the Array class.transposition: and fsmap methods in the FSNSArray category.fsmap method in the FSNSNumber category.asMutableString method in the FSNSString category.mod: method in the Number class.installTutorial method in the System class.
sign method has been added in the FSNSNumber category. This method answer 1 if the receiver is positive, 0 if the receiver equals 0, and -1 if it is negative.


> errorPtr := FSPointer objectPointer
> data := myObject dataWithContentsOfFile:'wrongPath' error:errorPtr
> errorPtr at:0
NSError "File “wrongPath” does not exist." Domain=NSCocoaErrorDomain Code=260 UserInfo={
NSFilePath = wrongPath;
NSUnderlyingError = NSError "POSIX error: No such file or directory" Domain=NSPOSIXErrorDomain Code=2;
}
anEmployee is a managed object with a salary property, you can write:anEmployee salaryanEmployee valueForKey:'salary'
attach:, which takes a managed object context as argument. For each entity associated with the managed object context, this method defines, in the workspace associated with the receiver, an NSArray which is given the same name as the entity and which contains all the managed objects corresponding to the entity at the time of invocation.myObjectContext is a managed object context associated with an Employee entity and a Department entity, then, after executing:sys attach:myObjectContextEmployee and Department. These arrays will contain the managed objects for their corresponding entities: the Employee array will contain all the employees and the Department array will contain all the departments.attach: is a convenience method. You still have full access to the CoreData framework and can use its various APIs to get access to managed objects.
[:object| object valueForKey:'akey'] are displayed as aKey in column's headers.


at: and at:put: methods. This makes F-Script more effective for dealing with Objective-C APIs involving custom C pointers.
at: defined for NSArrays by the FSNSArray category can now be invoked with an NSIndexSet as argument (in addition to the already supported argument types).
at:put: defined for NSMutableArrays by the FSNSMutableArray category now accepts whole arrays of indices, Boolean arrays and NSIndexSets, like the at: method. This makes it easy to replace several elements of the receiver at once.
> a := {10, 20, 30, 40, 50}
> a at:{0, 2} put:{'hello', 'world'}
> a
{'hello', 20, 'world', 40, 50}
> a at:{true, false, true, true, false} put:{999, -111, 66}
> a
{999, 20, -111, 66, 50}
> a at:(a > 40) put:0
> a
{0, 20, -111, 0, 0}
> indexSet := NSMutableIndexSet indexSet. indexSet addIndex:0. indexSet addIndex:3.
> a at:indexSet put:{'Hi', 'mom'}
> a
{'Hi', 20, -111, 'mom', 0}
> a at:indexSet put:33
> a
{33, 20, -111, 33, 0}
removeAt: defined for NSMutableArrays by the FSNSMutableArray category now accepts whole arrays of indices, Boolean arrays and NSIndexSets, like the at: method. This makes it easy to remove several elements of the receiver at once.bitAnd: returns the result of the bit-wise logical AND of the binary representation of the receiver and the binary representation of the argument.bitOr: returns the result of the bit-wise logical OR of the binary representation of the receiver and the binary representation of the argument.bitXor: returns the result of the bit-wise exclusive OR of the binary representation of the receiver and the binary representation of the argument.timesRepeat: method is now defined for NSNumbers by the FSNSNumber category. This method evaluates the argument, a block, the number of times represented by the receiver. An example is:
> i := 0
> 10 timesRepeat:[i := i + 1]
> i
10
random returns a random integer between 0 and the receiver - 1 (e.g., 5 random will return either 0,1, 2, 3, or 4).random: wich takes an number as argument, returns an array of size equal to the argument, of random integers between 0 and the receiver - 1. All the elements of the result have a different value and are returned in a random order.
seedRandom sets the value of the receiver as the seed for a new sequence of pseudo-random numbers to be used by random and random: to compute their results.rand method is now deprecated.
indexOfObject:, containsObject: etc.) has been improved.
-(void)installFlightTutorial on the predefined sys object (note that this method replaces the -(void)installTutorial method, which is now deprecated).
//), which have been deprecated a long time ago, are no longer supported.
:" are now supported.
- (id)initWithChar:(char)value;
- (id)initWithUnsignedChar:(unsigned char)value;
- (id)initWithShort:(short)value;
- (id)initWithUnsignedShort:(unsigned short)value;
- (id)initWithInt:(int)value;
- (id)initWithUnsignedInt:(unsigned int)value;
- (id)initWithLong:(long)value;
- (id)initWithUnsignedLong:(unsigned long)value;
- (id)initWithLongLong:(long long)value;
- (id)initWithUnsignedLongLong:(unsigned long long)value;
- (id)initWithFloat:(float)value;
- (id)initWithBool:(BOOL)value;
These methods come in addition to the existing initWithDouble: method, which is the designated initializer for this class.
inspectIn: or inspectIn:with: messages to a collection.

printString method.

> 'foo' cString
'foo'
> NSString stringWithCString:'foo'
'foo'
> 'foo' cString
Pointer to 0x1223629
> NSString stringWithCString:'foo' cString
'foo'
defaults write org.fscript.fscriptapp mapCharPointerToNSString YES to restore the old mapping behavior for the F-Script application, and type defaults write org.fscript.fscriptapp mapCharPointerToNSString NO to get back to the new behavior.defaults write org.fscript.fscriptapp logWhenMappingCharPointerToNSString YES to activate logging by the F-Script application, and type defaults write org.fscript.fscriptapp logWhenMappingCharPointerToNSString NO to disable logging. This user default is only useful when the mapCharPointerToNSString user default is also set to YES.-(FSSize *)size has been added to class Rectangle. Returns a Rectangle's extent as an FSSize object.-(id)fsmap of category FSNSNumber is deprecated.-(id)fsmap of category FSNSArray is deprecated.-(BOOL)hasFrac_bool of category FSNSNumber is deprecated.inspectIn: or inspectIn:with: messages to an NSArray. P inspectIn:sys 
P inspectIn:sys with:{#name, #salary, [:pilot | pilot salary >200000]}



(NSImage alloc initWithContentsOfFile:'/Library/Desktop Pictures/Nature/Ladybug.jpg') inspect
ABAddressBook sharedAddressBook people valueForProperty:kABLastNameProperty returns the names of people registered in your address book.
ABAddressBook sharedAddressBook people inspectIn:sys with:{ [:p| p valueForProperty:kABFirstNameProperty]
,[:p| p valueForProperty:kABLastNameProperty]
,[:p| p valueForProperty:kABOrganizationProperty]}

guardedValue: has been added to class Block. This method executes the receiver and returns the result. If an error occurs during execution, it displays the block call stack to the user and returns nil. This method is useful when you want a block to be the target of an NSControl (for instance a button). Instead of using value: as the action method, you may use this method in order to have the block inspector pops-up automatically in case of error.sort method of the Array class has been rewritten. The previous version of sort was not preserving pre-existing order among equal elements (that is, if two elements compared as equal, the order of their indices in the sorted array was undefined). The new version is "stable": it preserves pre-existing order among elements that are equal, which is quite useful in typical data-analysis use-cases.+(BOOL)validateSyntaxForIdentifier:(NSString *)identifier has been added to FSInterpreter. Returns YES if the argument conforms to the syntax of identifiers in the F-Script language.save and save: method will use keyed archiving. The load and load: methods are able to read keyed archives, as well as old-style archives. F-Script public classes support both archiving styles.< has been added to class FSBoolean.< has been added to class NSNumber (through the FSNSNumber category)browse and browse: have been added to the FSInterpreter class. Opens an object browser.browseKV and browseKV: have been added to the FSInterpreter class. Opens a key value object browser.truncated has been added to class Number. Answer an integer equal to the receiver truncated towards zero.prefix of class Array is deprecated. Use the prefixes method instead (same semantics).mod: of class Number is deprecated. Use the rem: method instead (same semantics). replication: is deprecated. Use replicate: instead. (same semantics).\\ of class Array and FSNSArray category is deprecated. Use the scan: method instead (same semantics).rotation: of class Array is deprecated. Use rotatedBy: instead (same semantics).transposition: of class Array is deprecated. Use transposedBy: instead (same semantics). asMutableString (provided by FSNSString) is deprecated.Copyright © 2010 Philippe Mougin