Alpha 7 is out (download here). Four main user visible changes:
Class instance variables
We now have support for class instance variables. In the following example, we use this capability to define a class that keeps track of how many times it has been instantiated:
MyClass : NSObject
{
"Define the class instance variable that will keep track of allocations"
allocationCount (class instance variable)
"The +initialize method is handy to initialize class instance variables"
+ (void)initialize
{
allocationCount := 0
}
"Perform the allocation"
+ alloc
{
allocationCount := allocationCount + 1.
^ super alloc
}
"Return how many times the class has been sent an alloc message"
+ allocationCount
{
^ allocationCount
}
}
New methods for compression
Compression and indexing used to be provided by the same methods (i.e. at: and derivatives such as at:put: and removeAt:). In F-Script 2.0, compression is done using a different set of methods: where:, where:put: and removeWhere:. Having dedicated methods for compression will make code clearer and will allow for interesting new features in a future version. Of course, the old way of doing compression still works for backward compatibility, but you are encouraged to switch to the new methods.
For those new to array programming, compression allows selecting some elements of an array. It takes an array of booleans as argument and selects the elements of the receiver whose positional matching element in the argument is true. For example, say we define the following array of numbers:
numbers := {-5, -6, 3, 4, -1, 10}
Here is how we can select the elements in our array that are positive:
numbers where: numbers > 0
Now, we remove all negative elements:
numbers removeWhere: numbers < 0
Finally, we replace elements equal to 10 by 100:
numbers where: numbers = 10 put: 100
In the end, our array is equal to {3, 4, 100}.
Mandatory return instruction
Returning a value from a method must be specified explicitly using a return instruction (a caret followed by an expression). For example, the following method returns the string ‘hello’ :
- myMethod
{
^ 'hello'
}
Prefixed classes
In F-Script 2.0 all public classes are now prefixed. Consequently, Array, Block, Number and System become FSArray, FSBlock, FSNumber and FSSystem. The old classes are still there for backward compatibility (with the exception of System), but are deprecated. Tricks are in place to ease the transition but if you have defined categories or subclasses, you must change them to relate to the new classes.
hello Mr. Mougin!
is there currently a syntax for extending an existing class as with an objc category? reading the source of alpha 6 i saw it was possible, but could not work out the syntax.
@j
Adding methods to an existing Objective-C class is not yet supported. Implementation of this feature is in progress, this is why you see related stuff in the source code.
Philippe