Defining Program Structure
Developing TACL Programs
2–8 107365 Tandem Computers Incorporated
Use the macro in Figure 2-4, defaultvars, to assign data to a set of empty variables.
The macro accepts a space-separated list of variables and nonempty values and calls
itself repeatedly until all arguments are processed. To run this macro, load the file that
contains the macro definition and then type:
12> defaultvars [
variable constant
[
variable constant
...] ]
Figure 2-4. Processing Macro Arguments
?SECTION defaultvars MACRO
== Any more pairs?
[#IF NOT [#EMPTY %1%] |THEN|
== Is this variable empty?
[#IF [#EMPTYV %1%] |THEN|
== The variable is empty; install default value
#SET %1% %2%
]
== Call self again, omitting the current pair.
%0% %3 TO *%
]
The following session shows how defaultvars works:
15> #PUSH a b c
16> defaultvars a 3 b 4 c 5
17> #OUTPUTV a
3
18> #OUTPUTV b
4
19> #OUTPUTV c
5
Saving Levels of Variables The #PUSH built-in function creates a new level for a user-defined or built-in variable.
If you push a variable twice, TACL creates two levels of the variable. A new level
remains in existence until you request a #POP, #UNFRAME, or #RESET FRAMES
operation.
The following code redefines the TACL OUT file, retrieves information from the
history buffer, saves the history information in a file named HISTFILE in the current
subvolume, and then restores the OUT file to its previous setting:
?SECTION historysave MACRO
#PUSH #OUT == Create a new level for #OUT
#SET #OUT histfile == Set OUT to HISTFILE
#HISTORY == Retrieve history information
#POP #OUT == Restore #OUT to its previous value