F-Script is an open-source interactive and scripting environment for Cocoa. For more informations, see the project home at http://www.fscript.org.
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:2000
anEmployee 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 salary
anEmployee 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:myObjectContext
Employee
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.enableJava
method on the current System object: sys enableJava
asClass
on a string. For instance, to get an object representing the java.util.Stack class, you just have to type the expression: 'java.util.Stack' asClass
new
method and play with it. Example:
> myStack := 'java.util.Stack' asClass new
> myStack
[]
> myStack push:'hello'
'hello'
> myStack
['hello']
> myStack push:55
55
> myStack push:NSApplication sharedApplication
NSApplication: 0x4459e0
> myStack
[hello, 55.0, NSApplication: 0x4459e0]
> myStack peek
NSApplication: 0x4459e0
> myStack empty
false
> myStack contains:55
true
You can even manipulate Java objects with the object browser.sys browse:myStack
Copyright © 2006 Philippe Mougin