AMT Datasouth PAL User Manual
Page 119
113
if
if
Description
Conditionally executes a procedure based upon a boolean value.
Usage
AnyBool TrueProc
if
AnyBool
Boolean. Value which determines whether or not PAL executes TrueProc. A
value of true instructs the interpreter to execute TrueProc. A value of false
instructs PAL to not execute TrueProc.
TrueProc
Procedure. The procedure for PAL to execute given a value of true for
AnyBool.
Comments
This operator provides the PAL programmer with the ability to optionally execute a given pro-
cedure. Typically the boolean value AnyBool would result from the execution of a comparison
operator like eq or gt.
The if operator removes both parameters from the stack before optionally invoking the specified
procedure. The if operator does not place any results onto the stack. However, the procedure may
place one or more results onto the stack if desired.
Hints
The following three PAL sequences perform entirely different functions.
1:
1 1 eq MyProc if
2:
1 1 eq /MyProc if
3:
1 1 eq {MyProc} if
The first example instructs PAL to execute the procedure MyProc before PAL executes the
operator if. As a result, the if operator will generate an error unless MyProc places a procedure
object onto the stack before terminating.
In the second example, when the if operator executes, it will encounter a boolean value (true)
followed by a literal name (/MyProc) on the stack. Since if expects a boolean value followed by a
procedure object, this will produce an error.
The third example shows the proper approach to conditionally execute the procedure MyProc. The
if operator will execute the procedure "{MyProc}". The procedure, in turn, executes the procedure
MyProc.
The specified procedure may also do more than just execute a saved procedure. The following ex-
ample sorts the values of the variables High and Low to correspond with their names.
High Low lt {/High Low /Low High def def} if