beautypg.com

Begin – AMT Datasouth PAL User Manual

Page 63

background image

57

begin

begin

Description

Pushes a dictionary onto the dictionary stack.

Usage

AnyDict

begin

AnyDict

Dictionary. Dictionary to push onto the dictionary stack.

Comments

The PAL interpreter searches the dictionary stack in order to locate values associated with names
the interpreter encounters during PAL code execution. The interpreter always searches for names
starting with the top-most dictionary on the dictionary stack. The interpreter continues searching
down the stack until it locates the name. Therefore, higher dictionaries on the stack can contain
definitions for names which supercede definitions in lower dictionaries.

The def operator allows the programmer to associate values with names within the top-most dic-
tionary on the dictionary stack. During initialization, the PAL interpreter automatically places the
special dictionary userdict on the top of the dictionary stack. This provides a default storage
location for definitions performed during simple printer operations.

This def operator and name look-up construct provides the programmer with many powerful ca-
pabilities. However, the most common use of the construct involves the definition of simple vari-
ables.

The begin operator gives the programmer the ability to install a new dictionary on the top of the
dictionary stack. The interpreter will then place any new definitions created by the def operator
into this new top-most dictionary rather than into userdict.

This allows the programmer to collect a series of definitions within a single dictionary dedicated to
that purpose. When the PAL code no longer requires the definitions, the programmer can use the
end operator to discard the top-most dictionary from the stack. Provided the programmer has not
created any secondary references to the dictionary, this has the affect of also discarding all
definitions contained within the dictionary.

Hints

The begin and end operators provide the simplest means for procedures to manage local vari-
ables. The following example shows a very ineffecient procedure which averages two numbers.
The procedure uses the begin and end operators to keep the variables First and Second local to
itself.

1:

/Average {

2:

<<>> begin

3:

/Second exch def

4:

/First exch def

5:

First Second add 2 div

6:

end

7:

} bind

def