RPL programming language

The RPL programming language (RPL meaning Reverse Polish LISP or, alternatively, ROM-based procedural language) is a handheld calculator system and application programming language used on Hewlett-Packard's engineering graphing RPN calculators of the HP-28, HP-48 and HP-49 series.

RPL is a structured programming language based on RPN but equally capable of processing algebraic expressions and formulae. RPL has many similarities to FORTH, both languages being stack-based, and of course the list-based LISP. Contrary to previous HP RPN calculators, which had a fixed four-level stack, the RPL stack is only limited by available calculator RAM.

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. [1] (http://www.hpcalc.org/hp48/docs/programming/rplman.zip) According to a quote by Dr. William Wickes, one of the original RPL developers, "the development team never calls it anything but (the initials) RPL." [2] (http://www.faqs.org/faqs/hp/hp48-faq/part2/)

Contents

Variants

In the internal low- to medium-level variant of RPL, called System RPL (or SysRPL), it is used on some earlier HP calculators as well as the aforementioned ones, as part of their operating system implementation language. This variant of RPL is not accessible to the calculator user without the use of external tools. 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, using only a safe subset of the available SysRPL commands. Commands available in the SysRPL variant don't contain the same level of error checking as those available in UserRPL, requiring a greater level of care while programming.

Control Blocks

Unlike FORTH, RPL control blocks are not strictly postfix. 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 a 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

External links

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools