previous contents next
Previous: SEnC Client Commands Next: A Simple Example

Variables

SEnC allows the definition of arbitrary string valued variables. The name of a variable is composed of upper and lower case letters, digits and the underscore character (``_''), always starting with a letter. Variable names are case sensitive.

Variable substitution occurs whenever a variable name enclosed in braces (e.g. ``{MyVar}'') occurs in a command.

All SEnC variables are global, i.e. once defined they can be accessed from any command, regardless of the context. In order to avoid variable collision conflicts when using variables in a function, SEnC supports explicit variable instancing using the client commands !new and !delete. A !new command always creates a new instance of the variable with the given name. This new topmost instance ``hides'' all lower level instances of the same variable (if any), so that all following !set commands and variable substitutions will act on this instance until either another new instance is created on to of the current one, or this instance is deleted. After a !delete command, the next lower instance, if one exists, becomes again accessible.

This mechanism of variable instancing makes it possible to write functions that will not cause problems even if they are called from other contexts in which the same variable name is already used for some other purpose. On the other hand, it is also possible to share variables between different contexts and/or functions, which is the default behavior when no new instances are created/deleted.

As the variable instancing is based on the explicit calls to !new and !delete, it is the user's (or ``SEnC programmer's'') responsibility to make sure that, for normal use, for each !new command there is a corresponding !delete command. Of course, a more advanced used can also use (or ``abuse''?) variable instancing for implementing more advanced mechanisms, such as e.g. a value stack, where !new is used as push and !delete as pop.

SEnC creates no variable on its own. But some variables, once they have been created, will take a special meaning:

ANSWER
Contains the last answer given to a !prompt command.
OUTPUT
Contains last output line received from the Enif server.
FILENAME
Contains the name of current input file.
LINENUMBER
Contains the current line number in current input file.
NOECHO
By default, SEnC echoes all output it receives from the Enif server (except for the OK/KO acknowledgments) to the standard output. If the variable NOECHO exists, the output received from the Enif server is not echoed.

Note that in order to be able to access any of the above variables, it must first be explicitly created, either on directly the command line or using a !set or !new client command.


previous contents next
Previous: SEnC Client Commands Next: A Simple Example

SEnC - A Sequential Enif Client, Heinz Spiess, May 2003