Reverse Polish LISP

from Wikipedia, the free encyclopedia

Reverse Polish LISP (RPL, rarely UPL) is a stack-based programming language similar to FORTH , in the Hewlett-Packard - calculators such as the HP-28 , HP 48 and newer series such as the HP-49 and HP-50 is used. The language was developed in 1984 at HP's Corvallis , Oregon subsidiary . The aim was to find a replacement for the operating software in pocket calculators, which was usually programmed in assembler .

description

RPL is a mixture of Forth , Lisp and Smalltalk . Forth is stack-oriented (arguments to be executed first on the stack, then the command is executed, e.g. << 1 1 + >>), Lisp is list-oriented (first list / formula on the stack, then it is resolved from the inside). E.g. << '1 + 1' EVAL >> is converted into << 1 1 + >> with the command EVAL. Likewise << 'SIN (45)' >> on the stack in << 45 SIN >>.

In addition, the computer on the system simulates a stack with limited memory space, whereby this actually only consists of addresses that lead to the memory content (indirect addressing). The memory content is then the object (number, complex number, matrix, formula etc.) that can be loaded for calculation and is only shown on the display at the end. If a stack operation is carried out (e.g. SWAP = swap), only the addresses in the stack are changed, but not the content. This makes the computer very fast. At the end of the calculations (after garbage collection ), the new content of the stack is shown on the display by an internal program.

background

An anecdote by one of the RPL developers involved, Dr. According to William Wickes, the name is arbitrary. Program code in RPL can be entered as with the reverse Polish notation (UPN / RPN). The Lisp language essentially has the property of using lists of any content as a data type, executing basic (Lisp) operations on them and operating on them with many RPL commands, such as:

{ 0 12,5 91,7 -43 } sin

or in algebraic mode:

sin({0;12,5;91,7;-43})

The range of commands differs between the various series of pocket calculators. More complex RPL programs are therefore not downward, but mostly upward compatible. There are two dialects of the language, the more comfortable user RPL and the hardware-related, but more powerful Sys RPL .

The use of the reverse Polish notation leads to an unfamiliar, but after familiarization, efficient command sequence in which the data to be processed is always recorded before the processing commands (elements are first placed on the stack, then an operator is applied to them).

example

The following example program outputs the numbers from 1 to 100 in the first line of the screen:

« 1 100 FOR I
   I 1 DISP
   NEXT
»

The program is processed by the computer as follows:

  • First the numbers 1 and 100 are put on the stack
  • The FOR command removes these two numbers from the stack again, saves them as the start and end value of the loop and recognizes the following identifier I as a run variable of the FOR statement (I is a global variable here)
  • The interior of the FOR loop begins with the next statement. First the current value of the variable I is placed on the stack.
  • The DISP command outputs a value to the display (DISPlay), with the value 1 specifying the first line of the display as the target of the output.
  • DISP removes both the value of I and the 1 from the stack and shows I on the first line of the display.
  • NEXT marks the end of the loop structure

In most cases, the transfer of arguments takes place in such a way that they are first placed on the stack and even control structures take these values ​​like functions as arguments. Even comparisons work like this:

« → a
  « IF a 1 >
    THEN a LOG
    ELSE a 1 +
    END
  »
»

Description of the example:

  • At the beginning of the program a value is fetched from the stack and shifted from → to the temporary variable a. The variable a only exists as long as the program is processed within the inner «».
  • The value in the local variables a and 1 are put on the stack.
  • The comparison> is like a mathematical operation (e.g. +), which removes a and 1 from the stack and instead puts the result of the comparison on the stack (0 = FALSE, 1 = TRUE).
  • The following statement THEN then takes the result of the comparison (0 or 1) from the stack and continues processing either after THEN to ELSE or after ELSE to END.

For execution in RPL, it is not relevant when the comparison value was provided as an argument for THEN. Alternatively, the line with the IF could look like this:

...
  « a 1 > IF
...

Individual evidence

  1. "HP 48G Series User Guide", Hewlett-Packard. Issue 4 (2/1994, 10/1996), HP part number 00048-90127, first published: 07/1993.
  2. http://www.hpcalc.org/hp48/docs/programming/rpl3.txt
  3. http://www.hpcalc.org/hp48/docs/programming/rplman.zip
  4. http://www.faqs.org/faqs/hp/hp48-faq/part2/