2-6 RPL Programming Examples
PAD program listing
Program: Comments:
"!
#D:K
Makes sure the object is in string form. (Strings
are unaffected by this command.)
Y;6E<!
452!D6J<!HH!z!
K<2<B:!
I!I!DYB2!'!
Repeats if the string contains fewer than 22
characters.
Loop-clause adds a leading space.
<=4!
End loop.
»
`OPAD K
Stores the program in PAD.
Checksum: # 6577d
Bytes: 57.5
PAD is demonstrated in the program BDISP.
PRESERVE (Save and Restore Previous Status)
PRESERVE stores the current calculator (flag) status, executes a program from the stack, and restores the
previous status.
Level 1 " Level 1
«program»
"
result of program
'program'
"
result of program
Techniques used in PRESERVE
! Preserving calculator flag status. PRESERVE uses RCLF (recall flags) to record the current status of the
calculator in a binary integer, and STOF (store flags) to restore the status from that binary integer.
! Local-variable structure. PRESERVE creates a local variable structure to briefly remove the binary
integer from the stack. Its defining procedure simply evaluates the program argument, then puts the binary
integer back on the stack and executes STOF.
! Error trapping. PRESERVE uses IFERR to trap faulty program execution on the stack and to restore flags.
DOERR shows the error if one occurs.