# HP 48gII Advanced User's Reference Manual Page 106

Graphing calculator.

Techniques used in "RPN
Recursion. The "RPN program calls itself as a subroutine. This powerful technique works just like calling
!
another subroutine as long as the stack contains the proper arguments before the program calls itself. In this
case the level 1 argument is tested first to be sure that it is an algebraic expression before "RPN is called
again.
Object Type-Checking. "RPN uses conditional branching that depends on the object type of the level 1
!
object.
Nested program Structures. "RPN nests IF...THEN...END structures inside FOR...NEXT loops inside a
!
IF...THEN... ELSE...END structure.
List Concatenation. The result list of objects in RPN order is built by using the ability of the + command to
!
sequentially append additional elements to a list. This is a handy technique for gathering results from a
looping procedure.
"RPN program listing
Program:
«
OBJ
IF OVER
THEN  n f
«
1 n
FOR i
NEXT
IF DUP TYPE 5. ‹
THEN 1 LIST
END
IF n 1 >
THEN 2 n
2-28 RPL Programming Examples
IF DUP TYPE 9. SAME
THEN RPN
END n ROLLD
START +
NEXT
Take the expression apart.
If the argument count is nonzero,
then store the count and the
function.
Begins local variable defining
procedure.
Begins FOR...NEXT loop, which
converts any algebraic arguments to
lists.
Tests whether argument is an
algebraic.
If argument is an algebraic, convert
it to a list first.
Roll down the stack to prepare for
the next argument.
Repeat the loop for the next
argument.
Tests to see if level 1 object is a list.
If not a list, then convert it to one.
Ends the IF...THEN...END
structure.
Tests to see if there is more than
one argument.
Combine all of the arguments into a
list.

49g+