RPL (programming language)

Last updated

RPL
Paradigm Concatenative (stack-based), [1] structured
Designed by Hewlett-Packard
First appeared1984 (1986)
OS HP calculators
Dialects
System RPL, User RPL
Influenced by
RPN, Forth, Lisp [2]

RPL is a handheld calculator operating system and application programming language used on Hewlett-Packard's scientific graphing RPN (Reverse Polish Notation) calculators of the HP 28, 48, 49 and 50 series, but it is also usable on non-RPN calculators, such as the 38, 39 and 40 series. Internally, it was also utilized by the 17B, 18C, 19B and 27S. [3]

Contents

RPL is a structured programming language based on RPN, but equally capable of processing algebraic expressions and formulae, implemented as a threaded interpreter. [4] RPL has many similarities to Forth, both languages being stack-based, as well as the list-based LISP. Contrary to previous HP RPN calculators, which had a fixed four-level stack, the dynamic stack used by RPL is only limited by available RAM, with the calculator displaying an error message when running out of memory rather than silently dropping arguments off the stack as in fixed-sized RPN stacks. [5]

RPL originated from HP's Corvallis, Oregon development facility in 1984 as a replacement for the previous practice of implementing the operating systems of calculators in assembly language. [3] The first calculator utilizing it internally was the HP-18C and the first calculator making it available to users was the HP-28C, both from 1986. [6] [3] The last pocket calculator supporting RPL, the HP 50g, was discontinued in 2015. [7] [8] [9] However, multiple emulators that can emulate HP's RPL calculators exist that run on a range of operating systems, and devices, including iOS and Android smartphones. There are also a number of community projects to recreate and extend RPL on newer calculators, like newRPL [10] [11] or DB48X, [12] [13] which may add features or improve performance. [14]

Variants

The internal low- to medium-level variant of RPL, called System RPL (or SysRPL) is used on some earlier HP calculators as well as the aforementioned ones, as part of their operating system implementation language. In the HP 48 series this variant of RPL is not accessible to the calculator user without the use of external tools, but in the HP 49/50 series there is a compiler built into ROM to use SysRPL. It is possible to cause a serious crash while coding in SysRPL, so caution must be used while using it. The high-level User RPL (or UserRPL) version of the language is available on said graphing calculators for developing textual as well as graphical application programs. All UserRPL programs are internally represented as SysRPL programs, but use only a safe subset of the available SysRPL commands. The error checking that is a part of UserRPL commands, however, makes UserRPL programs noticeably slower than equivalent SysRPL programs. The UserRPL command SYSEVAL tells the calculator to process designated parts of a UserRPL program as SysRPL code.

Control blocks

RPL control blocks are not strictly postfix. Although there are some notable exceptions, the control block structures appear as they would in a standard infix language. The calculator manages this by allowing the implementation of these blocks to skip ahead in the program stream as necessary.

Conditional statements

IF/THEN/ELSE/END

RPL supports basic conditional testing through the IF/THEN/ELSE structure. The basic syntax of this block is:

 IF condition THEN if-true [ELSE if-false] END

The following example tests to see if the number at the bottom of the stack is "1" and, if so, replaces it with "Equal to one":

 « IF 1 == THEN "Equal to one" END »

The IF construct evaluates the condition then tests the bottom of the stack for the result. As a result, RPL can optionally support FORTH-style IF blocks, allowing the condition to be determined before the block. By leaving the condition empty, the IF statement will not make any changes to the stack during the condition execution and will use the existing result at the bottom of the stack for the test:

 « 1 == IF THEN "Equal to one" END »

IFT/IFTE

Postfix conditional testing may be accomplished by using the IFT ("if-then") and IFTE ("if-then-else") functions.

IFT and IFTE pop two or three commands off the stack, respectively. The topmost value is evaluated as a boolean and, if true, the second topmost value is pushed back on the stack. IFTE allows a third "else" value that will be pushed back on the stack if the boolean is false.

The following example uses the IFT function to pop an object from the bottom of the stack and, if it is equal to 1, replaces it with "One":

 « 1 == "One" IFT »

The following example uses the IFTE function to pop an object from the bottom of the stack and, if it is equal to 1, replaces it with "One". If it does not equal 1, it replaces it with the string "Not one":

 « 1 == "One" "Not one" IFTE »

IFT and IFTE will evaluate a program block given as one of its arguments, allowing a more compact form of conditional logic than an IF/THEN/ELSE/END structure. The following example pops an object from the bottom of the stack, and replaces it with "One", "Less", or "More", depending on whether it is equal to, less than, or greater than 1.

 «    DUP 1 ==    « DROP "One" »    « 1 < "Less" "More" IFTE »    IFTE  »

CASE/THEN/END

To support more complex conditional logic, RPL provides the CASE/THEN/END structure for handling multiple exclusive tests. Only one of the branches within the CASE statement will be executed. The basic syntax of this block is:

 CASE    condition_1 THEN if-condition_1 END     ...   condition_n THEN if-condition_n END   if-none  END

The following code illustrates the use of a CASE/THEN/END block. Given a letter at the bottom of the stack, it replaces it with its string equivalent or "Unknown letter":

 «     CASE        DUP "A" == THEN "Alpha" END       DUP "B" == THEN "Beta" END       DUP "G" == THEN "Gamma" END       "Unknown letter"    END    SWAP DROP  @ Get rid of the original letter  »

This code is identical to the following nested IF/THEN/ELSE/END block equivalent:

 «     IF DUP "A" ==     THEN        "Alpha"     ELSE         IF DUP "B" == THEN           "Beta"        ELSE            IF DUP "G" == THEN              "Gamma"           ELSE              "Unknown letter"           END        END      END     SWAP DROP  @ Get rid of the original letter  »

Looping statements

FOR/NEXT

RPL provides a FOR/NEXT statement for looping from one index to another. The index for the loop is stored in a temporary local variable that can be accessed in the loop. The syntax of the FOR/NEXT block is:

index_from index_to FOR variable_name loop_statement NEXT

The following example uses the FOR loop to sum the numbers from 1 to 10. The index variable of the FOR loop is "I":

 «      0       @ Start with zero on the stack     1 10    @ Loop from 1 to 10     FOR I   @ "I" is the local variable        I +  @ Add "I" to the running total     NEXT    @ Repeat...  »

START/NEXT

The START/NEXT block is used for a simple block that runs from a start index to an end index. Unlike the FOR/NEXT loop, the looping variable is not available. The syntax of the START/NEXT block is:

 index_from index_to START loop_statement NEXT

FOR/STEP and START/STEP

Both FOR/NEXT and START/NEXT support a user-defined step increment. By replacing the terminating NEXT keyword with an increment and the STEP keyword, the loop variable will be incremented or decremented by a different value than the default of +1. For instance, the following loop steps back from 10 to 2 by decrementing the loop index by 2:

 « 10 2 START -2 STEP »

WHILE/REPEAT/END

The WHILE/REPEAT/END block in RPL supports an indefinite loop with the condition test at the start of the loop. The syntax of the WHILE/REPEAT/END block is:

 WHILE condition REPEAT loop_statement END

DO/UNTIL/END

The DO/UNTIL/END block in RPL supports an indefinite loop with the condition test at the end of the loop. The syntax of the DO/UNTIL/END block is:

 DO loop_statement UNTIL condition END

See also

Notes

1. ^ "RPL" is derived from Reverse Polish Lisp according to its original developers, [15] [16] [17] [18] [19] [20] while for a short time in 1987 HP marketing attempted to coin the backronym ROM-based Procedural Language for it. [2] [20] [21] In addition, the RPL initials are sometimes incorrectly interpreted as Reverse Polish Logic or Reverse Polish Language. [22]

Related Research Articles

Reverse Polish notation (RPN), also known as reverse Łukasiewicz notation, Polish postfix notation or simply postfix notation, is a mathematical notation in which operators follow their operands, in contrast to prefix or Polish notation (PN), in which operators precede their operands. The notation does not need any parentheses for as long as each operator has a fixed number of operands.

<span class="mw-page-title-main">HP 48 series</span> Series of graphing calculators

The HP 48 is a series of graphing calculators designed and produced by Hewlett-Packard from 1990 until 2003. The series includes the HP 48S, HP 48SX, HP 48G, HP 48GX, and HP 48G+, the G models being expanded and improved versions of the S models. The models with an X suffix are expandable via special RAM and ROM cards. In particular, the GX models have more onboard memory than the G models. The G+ models have more onboard memory only. The SX and S models have the same amount of onboard memory.

<span class="mw-page-title-main">HP 49/50 series</span> Series of graphing calculators by Hewlett-Packard

The HP 49/50 series are Hewlett-Packard (HP) manufactured graphing calculators. They are the successors of the popular HP 48 series.

<span class="mw-page-title-main">HP-35</span> First pocket scientific calculator

The HP-35 was Hewlett-Packard's first pocket calculator and the world's first scientific pocket calculator: a calculator with trigonometric and exponential functions. It was introduced in 1972.

<span class="mw-page-title-main">HP-65</span> Programmable handheld calculator with magnetic card reader

The HP-65 is the first magnetic card-programmable handheld calculator. Introduced by Hewlett-Packard in 1974 at an MSRP of $795, it featured nine storage registers and room for 100 keystroke instructions. It also included a magnetic card reader/writer to save and load programs. Like all Hewlett-Packard calculators of the era and most since, the HP-65 used Reverse Polish Notation (RPN) and a four-level automatic operand stack.

<span class="mw-page-title-main">HP-42S</span>

The HP-42S RPN Scientific is a programmable RPN Scientific hand held calculator introduced by Hewlett-Packard in 1988. It has advanced functions suitable for applications in mathematics, linear algebra, statistical analysis, computer science and others.

<span class="mw-page-title-main">HP-18C</span>

The HP-18C is a Hewlett-Packard business calculator which was quickly followed by the very similar but greatly improved HP-19B. The HP-18C is HP's first RPL-based calculator internally, even though this was not visible on user-level in this non user-programmable model. The user has a solver available, but only had about 1.5 KB of continuous memory available to store equations.

<span class="mw-page-title-main">HP calculators</span> Calculator product line by Hewlett-Packard

HP calculators are various calculators manufactured by the Hewlett-Packard company over the years.

There are various ways in which calculators interpret keystrokes. These can be categorized into two main types:

<span class="mw-page-title-main">Hewlett-Packard Voyager series</span> Programmable calculator, 1982–1984

The Hewlett-Packard Voyager series of calculators were introduced by Hewlett-Packard in 1981. All members of this series are programmable, use Reverse Polish Notation, and feature continuous memory. Nearly identical in appearance, each model provided different capabilities and was aimed at different user markets.

<span class="mw-page-title-main">HP Saturn</span> Family of 4-bit datapath microprocessors

The Saturn family of 4-bit (datapath) microprocessors was developed by Hewlett-Packard in the 1980s first for the HP-71B handheld computer and then later for various HP calculators. It succeeded the Nut family of processors used in earlier calculators. The original Saturn chip was first used in the HP-71B hand-held BASIC-programmable computer, introduced in 1984. Later models of the family powered the popular HP 48 series of calculators. The HP48SX and HP48S were the last models to use genuine Saturn processors manufactured by HP. Later calculator models used Saturn processors manufactured by NEC. The HP 49 series initially used the Saturn CPU as well, until the NEC fab could no longer manufacture the processor for technical reasons in 2003. Therefore, starting with the HP 49g+ model in 2003, the calculators switched to a Samsung S3C2410 processor with an ARM920T core which ran an emulator of the Saturn hardware in software. In 2000, the HP 39G and HP 40G were the last calculators introduced based on the actual NEC fabricated Saturn hardware. The last calculators based on the Saturn emulator were the HP 39gs, HP 40gs and HP 50g in 2006, as well as the 2007 revision of the hp 48gII. The HP 50g, the last calculator utilizing this emulator, was discontinued in 2015 when Samsung stopped producing the ARM processor on which it was based.

<span class="mw-page-title-main">HP-28 series</span> Series of graphing calculators produced by Hewlett-Packard

The HP-28C and HP-28S were two graphing calculators produced by Hewlett-Packard from 1986 to 1992. The HP-28C was the first handheld calculator capable of solving equations symbolically. They were replaced by the HP 48 series of calculators, which grew from the menu-driven RPL programming language interface first introduced in these HP-28 series.

HP 39/40 series are graphing calculators from Hewlett-Packard, the successors of HP 38G. The series consists of six calculators, which all have algebraic entry modes, and can perform numeric analysis together with varying degrees of symbolic calculation. All calculators in this series are aimed at high school level students and are characterized by their ability to download APLETs or E-lessons. These are programs of varying complexity which are generally intended to be used in the classroom to enhance the learning of mathematics by the graphical and/or numerical exploration of concepts.

<span class="mw-page-title-main">HP 35s</span> Programmable scientific calculator produced by Hewlett-Packard

The HP 35s (F2215A) is a Hewlett-Packard non-graphing programmable scientific calculator. Although it is a successor to the HP 33s, it was introduced to commemorate the 35th anniversary of the HP-35, Hewlett-Packard's first pocket calculator. HP also released a limited production anniversary edition with shiny black overlay and engraving "Celebrating 35 years".

A graphing calculator is a class of hand-held calculator that is capable of plotting graphs and solving complex functions. While there are several companies that manufacture models of graphing calculators, Hewlett-Packard is a major manufacturer.

<span class="mw-page-title-main">HP-55</span>

The HP-55 was a programmable handheld calculator, a lower-cost alternative to the HP-65. Introduced by Hewlett-Packard in 1975, it featured twenty storage registers and room for 49 keystroke instructions. Its outward appearance was similar to the HP-65, but its silver band went through between the display and the keyboard like HP-45, and the functions of some keys were different from HP-65, and it did not have a magnetic card reader/writer. Like all Hewlett-Packard calculators of the era and most since, the HP-55 used Reverse Polish Notation (RPN) and a four-level automatic operand stack.

<span class="mw-page-title-main">HP Prime</span> Programmable graphing calculator

The HP Prime Graphing Calculator is a graphing calculator introduced by Hewlett-Packard in 2013 and manufactured by HP Inc. until the licensees Moravia Consulting spol. s r.o. and Royal Consumer Information Products, Inc. took over the continued development, manufacturing, distribution, marketing and support in 2022. It was designed with features resembling those of smartphones, such as a full-color touchscreen display and a user interface centered around different applications. It claims to be the world's smallest and thinnest CAS-enabled calculator currently available.

Christophe de Dinechin is a French computer scientist, with contributions in video games, programming languages and operating systems.

The RPL character set is an 8-bit character set and encoding used by most RPL calculators manufactured by Hewlett-Packard as well as by the HP 82240B thermo printer. It is sometimes referred to simply as "ECMA-94" in documentation, although it is for the most part a superset of ISO/IEC 8859-1 / ECMA-94 in terms of printable characters, and it differs from ISO/IEC 8859-1 by using displayable characters rather than control characters in the 0x80 to 0x9F range of code points.

In computing FOCAL character set refers to a group of 8-bit single byte character sets introduced by Hewlett-Packard since 1979. It was used in several RPN calculators supporting the FOCAL programming language, like the HP-41C/CV/CX as well as the later HP-42S, which was introduced in 1988 and produced up to 1995. As such, it is also used by SwissMicros' DM41/L, both introduced in 2015, and is implicitly supported by the DM42, introduced in 2017.

References

  1. "The Joy of Programming?". Museum of HP Calculators. 2020. Archived from the original on 2021-12-03.
  2. 1 2 Patton, Charles M. (August 1987). "Computation for Handheld Calculators" (PDF). Hewlett-Packard Journal . 38 (8). Palo Alto, California, USA: Hewlett-Packard Company: 21–25. Archived from the original (PDF) on 2011-12-06. Retrieved 2015-09-12.
  3. 1 2 3 Hewlett-Packard. "RPLMan from Goodies Disk 4" (RPLMAN.ZIP). Retrieved 2015-09-12.
  4. Horn, Joseph K. "What is RPL?". Archived from the original on 2017-09-17. Retrieved 2017-09-17.
  5. Wessman, Timothy "Tim" James (2016-06-21) [2016-06-20]. "What to do with stack overflow OBJ->/LIST->?". MoHPC - The Museum of HP Calculators. Archived from the original on 2023-09-24. Retrieved 2023-09-24.
  6. Wickes, William C. (January–February 1987). "The HP-28C: An Insider's Perspective". HPX Exchange. 1 (1).
  7. Kuperus, Klaas (2015-03-04). "HP 50g: End of an era". Moravia. Archived from the original on 2015-04-02.
  8. Kuperus, Klaas (2015-03-06). "HP 50g not so good news?". Moravia. Retrieved 2016-01-01.
  9. Wessman, Timothy "Tim" James (2015-12-26). "Windows 10 won't allow HP 50g USB drivers to be installed". MoHPC - The Museum of HP Calculators. Retrieved 2016-01-01.
  10. Lapilli, Claudio Daniel (2014-01-03). "newRPL" . Retrieved 2015-09-12. (an open source RPL derivative for the HP 50g and HP 49g+, the HP 40gs, HP 39gs and hp 39g+ as well as the HP Prime)
  11. Lapilli, Claudio Daniel (2021-07-23) [2014]. "newRPL Documentation Project". newRPL. Archived from the original on 2023-11-03. Retrieved 2023-10-23.
  12. de Dinechin, Christophe (2022). "DB48X on DM42 - RPL runtime for the DM42 calculator, in the spirit of HP48/49/50". DB48X. Archived from the original on 2023-11-03. Retrieved 2023-10-23.
  13. de Dinechin, Christophe (2023-02-03). "Reviving Reverse Polish Lisp - Building an open-source HP48-like calculator". FOSDEM . Archived from the original on 2023-10-03. Retrieved 2023-10-03. (NB. An improved derivative of RPL called DB48X for the SwissMicros DM42 and DM32.)
  14. Lapilli, Claudio Daniel (2014-10-31). "N-Queens on 50g (RPL language)". MoHPC - The Museum of HP Calculators. Archived from the original on 2023-11-03. Retrieved 2023-10-23.
  15. Wickes, William C. (1988-10-01) [14–18 June 1988]. Forsely, Lawrence P. (ed.). RPL: A Mathematical Control Language. Proceedings of the 1988 Rochester Forth Conference: Programming Environments. Vol. 8. Rochester, New York, USA: Institute for Applied Forth Research, Inc., University of Rochester. pp. 27–32. ISBN   978-0-91459308-9. OCLC   839704944. Several existing operating systems and languages were considered, but none could meet all of the design objectives. A new system was therefore developed, which merges the threaded interpretation of Forth with the functional approach of Lisp. The resulting operating system, known unofficially as RPL (for Reverse-Polish Lisp), made its first public appearance in June of 1986 in the HP-18C Business Consultant calculator. (NB. This title is often cited as "RPL: A Mathematics Control Language". An excerpt is available at: )
  16. Wickes, William C. (1991-03-11). "RPL stands for Reverse Polish Lisp". www.hpcalc.org. Retrieved 2015-09-12. RPL stands for Reverse Polish Lisp. In the early days of RPL development, we got tired of calling the unnamed system "the new system", and one of the development team came up with "RPL", both as a play on "RPN" which has been the loved/hated hallmark of HP calcs forever, and as an accurate indication of the derivation of the language from Forth and Lisp.
    RPL was never particularly intended to be a public term; at the time of the HP Journal article (August 1987) on the HP 28C there was an attempt to create a less whimsical name--hence "ROM-based procedural language", which preserved the initials but had a more dignified sound. The development team never calls it anything but (the initials) RPL. You can choose either of the two full-word versions that you prefer. Or how about "Rich People's Language?" Bill Wickes, HP Corvallis.
  17. Schoorl, André (2000-04-04) [1997]. "HP48 Frequently Asked Questions List". HP Calculator Archive. p. 69. Retrieved 2015-09-12.
  18. "I've heard the names RPL, Saturn, STAR, GL etc... What are they? - RPL". FAQ: 2 of 4 - Hardware, Programs, and Programming. 4.62. comp.sys.hp48. 2000-04-14. 8.1. Retrieved 2015-09-12.
  19. Nelson, Richard J. (2012-04-04). "HP RPN Evolves" (PDF). HP Solve (27). Hewlett-Packard: 30–32. Retrieved 2015-09-12.
  20. 1 2 Mier-Jędrzejowicz, Włodzimierz "Włodek" Anthony Christopher (July 1991). A Guide to HP Handheld Calculators and Computers (5 ed.). HHC 2011. ISBN   978-1-88884030-8. 1888840307. RPL stands for Reverse Polish Lisp - it combined the RPN calculator language of earlier models with features of the Lisp and Forth programming languages. For a time HP explained the letters RPL as an acronym for "ROM-based Procedural Language".
  21. "HP Celebrates 35 Years of Handheld Calculator Innovation". Hewlett-Packard Development Company, L.P. 2007. Archived from the original on 2007-03-17. Retrieved 2015-09-13. 1987: HP-28C: First full RPL calculator: In the late 1980s, HP developed a new programming language for its new series of extremely powerful calculators. By combining elements of RPN, Lisp and Forth, HP came up with a language called RPL (or ROM-based Procedural Language).
  22. Rechlin, Eric; Marangon, Carlos. "HPedia: The HP Calculator Encyclopedia". www.hpcalc.org. Retrieved 2020-04-20.
  23. http://h41268.www4.hp.com/live/index_e.aspx?qid=20709&jumpid=va_r11363_us/en/any/tsg/pl_ot_ob_ds_pd/calculatoremulators_cc/dt%5B%5D
  24. http://www.calculatrices-hp.com/index.php?page=emulateurs
  25. "Emulator of HP 50g with #2.16 ROM".
  26. http://www.calculatrices-hp.com/uploads/emulateurs/HP50gVirtualCalculatorSetup_3_1_30.zip

Further reading