Reference Guide

2-14 RPL Programming Examples
MULTI (Multiple Execution)
Given an object and a program that acts on the object, MULTI applies the program to the object repeatedly until
the program no longer changes the object.
Level 2 Level 1
Level 1
object «progra
object
result
Techniques used in MULTI
DO…UNTIL…END (indefinite loop). The DO clause contains the steps to be repeated. The UNTIL clause
contains the test that repeats both clauses again (if false) or exits (if true).
Programs as arguments. Although programs are commonly named and then executed by calling their names,
programs can also be put on the stack and used as arguments to other programs.
Evaluation of local variables. The program argument to be executed repeatedly is stored in a local variable.
It’s convenient to store an object in a local variable when you don’t know beforehand how many copies you’ll
need. An object stored in a local variable is simply put on the stack when the local variable is evaluated. MULTI
uses the local variable name to put the program argument on the stack and then executes EVAL to execute the
program.
MULTI program listing
Program: Comments:
«
→ p
Creates a local variable p that contains the
program from level 1.
«
Begins the defining procedure.
DO
Begins the DO loop clause.
DUP
Makes a copy of the object, now in level 1.
p EVAL
Applies the program to the object,
returning its new version.
DUP
Makes a copy of the new object.
ROT
Moves the old version to level 1.
UNTIL
Begins the DO test clause.
SAME
Tests whether the old version and the new
version are the same.
END
Ends the DO structure.
»
Ends the defining procedure.
»
`O
MULTI K
Stores the program in MULTI.
Checksum: # 22693d
Bytes: 56
MULTI is demonstrated in the next programming example.