As of version 1.3.0, gretl contains a mechanism for defining functions in the context of a script. The syntax for this is somewhat similar to the bash shell. Details follow. At this point the mechanism is not "set in stone", and I welcome comments and suggestions. I also welcome help in shaking out any bugs.