evaluation

A Builtin Command is any of the commands listed under "commands". All builtin commands start with "/". All builtins have a return value, usually nonzero for success and 0 for failure.

A Macro Command is a user-defined command. Macro commands also start with '/'. The return value of a macro is the return value of its body when executed.

A command starting with a single "/" is either a Macro Command or a Builtin Command. If the "/" is followed by "!", the return value of the command will be negated. If the "/" or "/!" is followed by "@", the rest of the word is interpreted as the name of a Builtin Command. If the "/" or "/!" is followed by "#", the rest of the word is interpreted as the number of a macro. If neither "@" nor "#" is used (the normal case), the rest of the word is interpreted as a macro if there is one with that name, otherwise it is interpreted as the name of a Builtin Command. If the name does not match any macro or Builtin Command, the NOMACRO hook is called.

A Simple Command is any command that does not start with "/". The text of such a command is sent directly to the current world, if there is one. The return value of a simple command is 1 if the text is successfully sent to the current world, otherwise 0. To send a line that starts with "/" without having it interpreted as a Macro Command or Builtin Command, use a leading "//"; the first "/" will be stripped.

A Compound Command is one of /IF.../ENDIF or /WHILE.../DONE. These are described under separate help sections. Their return value is that of the last command executed.

A List is a sequence of commands separated by "%;" (separator) or "%|" (pipe) tokens. The commands are executed in sequence, but may be aborted early with the /RETURN or /BREAK commands. and the return value of the List is the return value of the last command executed in the sequence. An empty List has a return value of 1.

Two commands separated by "%|" pipe token mentioned above will have the output stream (tfout) of the first connected to the input stream (tfin) of the second. The first command runs to completion before the second command begins; the second command should stop reading tfin when it becomes empty. Simple Commands have no tfin or tfout, so they may not be piped. The tfout of a Compound Command may not be piped directly, but the output of a macro that contains a Compound Command may be piped.

Some characters within a macro body undergo substitution. These special characters are not interpreted as themselves, but cause some evaluation to be performed, and the result substituted in place of these characters. This is described under "substitution".

When an expansion begins, a new scope is created. Any local variables created during the expansion will be placed in this new scope. The scope and all variables in it are destroyed when the expansion exits.

Any variable reference will refer to the variable with that name in the nearest enclosing (i.e., most recently created) still existing scope. This is called "dynamic scope".

Lexical scope can be simulated to some extent by using variable substitutions with the correct number of "%"s instead of variable references. (Remember, a "reference" uses the name by itself in an expression, like "/test foo"; a "substitution" uses "%" characters, like "/test %foo").

See: commands, macros, substitution, /if, /while


Back to index
Back to tf home page
Copyright © 1995 - 1999 Ken Keys