Reference Guide

RPL Programming Examples 2-25
NAMES (Check List for Exactly Two Names)
If the argument for a program is a list (as determined by VFY), NAMES verifies that the list contains exactly two
names. If the list does not contain exactly two names, an error message appears in the status area and program
execution is aborted.
Level 1
Level 1
{ valid list }
{ invalid list }
(error message in status area)
Techniques used in NAMES
Nested conditionals. The outer conditional verifies that there are two objects in the list. If so, the inner
conditional verifies that both objects are names.
Logical functions. NAMES uses the AND command in the inner conditional to determine if both objects are
names, and the NOT command to display the error message if they are not both names.
NAMES program listing
Program: Comments:
«
IF
Starts the outer conditional structure.
OBJ
Returns the n objects in the list to levels
2 through (n + 1), and returns the list
size n to level 1.
DUP 2. SAME
Copies the list size and tests if it’s 2.
THEN
DROP
IF
If the size is 2, moves the objects to
level 1 and 2, and starts the inner
conditional structure.
TYPE 6. SAME
Tests if the object is a name: returns 1 if
so, otherwise 0.
SWAP TYPE 6. SAME
Moves the second object to level 1, then
tests if it is a name (returns 1 or 0).
AND
Combines test results: Returns 1 if both
tests were true, otherwise returns 0.
NOT
Reverses the final test result.
THEN
"List needs two names"
DOERR
If the objects are not both names,
displays an error message and aborts
execution.
END
Ends the inner conditional structure.
ELSE
DROPN
"Illegal list size"
DOERR
If the list size is not 2, drops the list size,
displays an error message, and aborts
execution.
END
Ends the outer conditional.
»
`O
NAMES K
Stores the program in NAMES.