I usually write my scripts using an external text editor and save them
as text files. I express them in the form of blocks literals (i.e.,
code between brackets) so I can easily load them programmatically
from F-Script, if needed, using NSString methods such as
"stringWithContentsOfFile:encoding:error:" combined with FSSystem's
"blockFromString:" method.
To programmatically save a block from F-Script to a text file you just
have to get its source code in an NSString, using the "description"
method, and then to write that string to a file using a standard Cocoa
method such as "writeToFile:atomically:encoding:error:".
There are some script I always want to have loaded in my environment,
ready to use. Fo this, I just add loading instructions in the latent
block (see the documentation).
Blocks also support the standard Cocoa object archiving system
(NSCoding protocol). You can use that too to save your blocks, or even
complex objects graphs (for example, whole collections of blocks). The
difference is that it saves blocks as objects, in some kind of binary
format. In addition to the standards Cocoa method, F-Script offers
some handy extensions for performing this. For instance, try this in F-
Script:
myBlock := [:a :b| a + b].
myBlock save.
Then to load:
sys load
See also the save: and load: methods.
Philippe