Chapter 4. Values of Atoms
4.1. General 
There are two kinds of "value" which can be attached to an
ATOM can have either, both, or neither. They interact in no way
(except that alternately referring to one and then the other is
inefficient). These two values are referred to as the local value
and the global value of an
ATOM. The terms "local" and "global"
are relative to
PROCESSes (chapter 20), not functions or programs.
SUBRs which reference the local and global values of an
and some of the characteristics of local versus global values, follow.
4.2. Global Values
4.2.1. SETG 
A global value can be assigned to an
ATOM by the
global"), as in
<SETG atom any>
where atom must
EVAL to an
ATOM, and any can
EVAL of the second argument becomes the global value of
EVAL of the first argument. The value returned by the
SETG is its
second argument, namely the new global value of atom.
<SETG FOO <SETG BAR 500>>$ 500
The above made the global values of both the
FOO and the
BAR equal to the
FIXed-point number 500.
<SETG BAR FOO>$ FOO
That made the global value of the
BAR equal to the
4.2.2. GVAL 
GVAL ("global value") is used to reference the global
value of an
returns as a value the global value of atom. If atom does not
evaluate to an
ATOM, or if the
ATOM to which it evaluates has no
global value, an error occurs.
GVAL applied to an
ATOM anywhere, in any
PROCESS, in any
function, will return the same value. Any
SETG anywhere changes the
global value for everybody. Global values are context-independent.
READ understands the character
, (comma) as an abbreviation for an
GVAL to whatever follows it.
GVAL into the comma format. The
following are absolutely equivalent:
,atom <GVAL atom>
Assuming the examples in section 4.2.1 were carried out in the order given, the following will evaluate as indicated:
,FOO$ 500 <GVAL FOO>$ 500 ,BAR$ FOO ,,BAR$ 500
4.2.3. Note on SUBRs and FSUBRs
GVALs of the
ATOMs used to refer to MDL "built-in"
Subroutines are the
FSUBRs which actually get applied
ATOMs are referenced. If you don't like the way those
supplied routines work, you are perfectly free to
to your own versions.
("global unassign") causes atom to have no assigned global value, whether or not it had one previously. The storage used for the global value can become free for other uses.
4.3. Local Values
4.3.1. SET 
SET is used to assign a local value to an
SET are of the form
<SET atom any>
EVAL of any just like
<SET BAR <SET FOO 100>>$ 100
FOO have been given local values equal to the
FIXed-point number 100.
<SET FOO BAR>$ BAR
FOO has been given the local value
Note that neither of the above did anything to any global values
BAR might have had.
4.3.2. LVAL 
SUBR used to extract the local value of an
ATOM is named
LVAL. As with
READ understands an abbreviation for an
LVAL: the character
. (period), and
EVAL operates on the corresponding MDL object, it returns the
current local value of atom:
<LVAL atom> .atom
The local value of an
ATOM is unique within a
ATOM in one
PROCESS has no effect on its
LVAL in another
PROCESS, because each
PROCESS has its own "control stack"
(chapters 20 and 22).
Assume all of the previous examples in this chapter have been done. Then the following evaluate as indicated:
.BAR$ 100 <LVAL BAR>$ 100 .FOO$ BAR ,.FOO$ FOO
causes atom to have no assigned local value, whether or not it had one previously.
VALUE is a
SUBR which takes an
ATOM as an argument, and then:
- if the
LVAL, returns the
- if the
LVALbut has a
GVAL, returns the
- if the
ATOMhas neither a
LVAL, calls the
This order of seeking a value is the opposite of that used when an
ATOM is the first element of a
FORM. The latter will be called the
G/LVAL, even though that name is not used in MDL.
<UNASSIGN A>$ A <SETG A 1>$ 1 <VALUE A>$ 1 <SET A 2>$ 2 <VALUE A>$ 2 ,A$ 1