AMT Datasouth PAL User Manual
Page 83
![background image](/manuals/733850/83/background.png)
77
def
def
Description
Stores a data value under a specified key in the top-most dictionary on the dictionary stack.
Usage
KeyAny DataAny
def
KeyAny
Any type. Key under which to store the specified object.
DataAny
Any type. Object to store under the specified key.
Comments
Both KeyAny and DataAny may be of any type. However, the interpreter provides special opti-
mized handling of name objects when used as dictionary entry keys. As a result, if the programmer
specifies a string for KeyAny, the interpreter automatically converts the string to a literal name
before storing the key into the dictionary. In addition, names provide the easiest means for
recalling the DataAny object at a future time.
The programmer can use the def operator to save any data object, including complex data objects
such as dictionaries, arrays, and procedures into the printer's memory. If a name object was used
for KeyAny, the programmer or procedures written by the programmer can later recall these data
objects onto the operand stack by simply specifying KeyAny.
If an entry for KeyAny already exists in the top dictionary on the dictionary stack, def replaces the
old DataAny in the dictionary's entry with the new DataAny.
During printer initialization, the PAL interpreter creates an empty dictionary named userdict. The
interpreter then places this dictionary on the top of the dictionary stack. Unless the PAL
programmer places another dictionary above userdict on the dictionary stack, the def operator will
store KeyAny and DataAny into userdict. The PAL interpreter provides this dictionary for
exactly this purpose. userdict provides an easily accessible location for storing data objects and
procedures.
Hints
Using name objects as the KeyAny parameter serves the same basic purpose as variables in other
programming languages. The def operator provides the same basic purpose as assigning a value to
a variable. However, the def operator also provides the means to store PAL procedures within the
printer's memory. The host computer can later invoke these procedures to perform various desired
actions. Other procedures can also invoke these procedures in a manner similar to using
subroutines or functions in other programming languages.