RPL (programming language): Difference between revisions

Content deleted Content added
CE
CE, improved refs
Line 2:
{{About||the programming language for the Commodore PET/CBM computers|Reverse Polish Language|the compiled database programming language|Real-time Programming Language}}
{{Use dmy dates|date=April 2019|cs1-dates=y}}
{{Use list-defined references|date=October 2023}}
{{Infobox programming language
| name = RPL
| logo =
| paradigm = [[stack-oriented programming language|Stack]], [[structured programming|structured]], [[concatenative programming language|concatenative]],<ref name="Joy_2020"/> partially [[object-oriented]]<ref name="Urroz_2000"/><ref name="RPL_2023"/><ref name="RPL_2003"/>
| paradigm = [[stack-oriented programming language|Stack]], [[structured programming|structured]], [[concatenative programming language|concatenative]],<ref>{{Cite web |url=https://www.hpmuseum.org/forum/showthread.php?mode=linear&tid=15509&pid=135732 |title=The Joy of Programming? |publisher=Museum of HP Calculators |date=2020 |archive-url=https://web.archive.org/web/20211203131528/https://www.hpmuseum.org/forum/showthread.php?mode=linear&tid=15509&pid=135732 |archive-date=2021-12-03}}</ref> partially [[object-oriented]]<ref>{{cite book |author-first=Gilberto E. |author-last=Urroz |title=Programming the HP 49 G Calculator in User RPL Language |date=2000 |url=https://h30434.www3.hp.com/psg/attachments/psg/palm-webossoftware/252122/1/hp49g04.pdf |archive-url=https://web.archive.org/web/20221031143355/https://h30434.www3.hp.com/psg/attachments/psg/palm-webossoftware/252122/1/hp49g04.pdf |archive-date=2022-10-31}}</ref><ref>{{cite web |url=https://www.hpmuseum.org/rpl.htm |title=RPL |publisher=Museum of HP Calculators |archive-url=https://web.archive.org/web/20230820203818/https://www.hpmuseum.org/rpl.htm |archive-date=2023-08-20}}</ref><ref>{{cite web |url=https://archived.hpcalc.org/museumforum/thread-35921.html |title=RPN/RPL — What? |date=2003 |publisher=Museum of HP Calculators |archive-url=https://web.archive.org/web/20230820204017/https://archived.hpcalc.org/museumforum/thread-35921.html |archive-date=2023-08-20}}</ref>
| year = 1984 (1986)
| designer = [[Hewlett-Packard]]
| developer =
| latest_release_version = <!-- X.Y.Z/{{release date|df=yes|YYYY|MM|DD}} -->
| latest_release_date = 2012-04-26<!-- HP 50g 2.16 --><ref name="HP_4"/><ref name="HP_7"/><ref name="HP_5"/><ref name="HP_6"/>
| latest_release_date = 2012-04-26<!-- HP 50g 2.16 --><ref name="HP_4">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{{dead link|date=April 2018 |bot=InternetArchiveBot|fix-attempted=yes}}</ref><ref name="HP_7">http://www.calculatrices-hp.com/index.php?page=emulateurs<!-- https://web.archive.org/web/20170917223308/http://www.calculatrices-hp.com/index.php?page=emulateurs --></ref><ref name="HP_5">{{Cite web|url=http://www.hpmuseum.org/forum/thread-4405-post-39600.html|title=Emulator of HP 50g with #2.16 ROM}}</ref><ref name="HP_6">http://www.calculatrices-hp.com/uploads/emulateurs/HP50gVirtualCalculatorSetup_3_1_30.zip<!-- https://web.archive.org/web/20170917095533/http://www.calculatrices-hp.com/uploads/emulateurs/HP50gVirtualCalculatorSetup_3_1_30.zip --></ref>
| discontinued = 2015<!-- HP 50g -->
| typing =
Line 17 ⟶ 18:
| influenced_by = [[Reverse Polish Notation|RPN]], [[Forth (programming language)|Forth]], [[Lisp (programming language)|Lisp]]<ref name="HPJ38"/>
| influenced =
| operating_system = [[Hewlett-Packard|HP]] [[calculatorscalculator]]s
| license =
| website =
Line 26 ⟶ 27:
RPL is a [[structured programming]] language based on RPN, but equally capable of processing [[infix notation|algebraic]] expressions and formulae, implemented as a [[threaded code|threaded interpreter]].<ref name="RPL3"/> RPL has many similarities to [[Forth (programming language)|Forth]], both languages being [[stack-oriented programming language|stack]]-based, as well as the list-based [[LISP]]. Contrary to previous HP RPN calculators, which had a fixed [[4-level RPN|four-level stack]], the [[dynamic RPN stack|dynamic stack]] used by RPL is only limited by available [[random-access memory|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.<ref name="Wessman_2016"/>
 
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]].<ref name="RPLMAN"/> The last pocket calculator supporting RPL, the HP 50g, was discontinued in 2015.<ref name="Kuperus_2015_1"/><ref name="Kuperus_2015_2"/><ref name="Wessman_2015"/> However, <!-- an [[Mobile app|app]] is available for [[Android (operating system)|Android]], go49gp[https://play.google.com/store/apps/details?id=o2s.emul.hp49gp&hl=en_US], which emulates the HP 49g+/50g and will run RPL programs. --> 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]] or [[DB48X]].
 
==Variants==
The internal low- to medium-level variant of RPL, called '''[[HP 49 series#Programming|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&nbsp;48 series this variant of RPL is not accessible to the calculator user without the use of external tools, but in the HP&nbsp;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 [[Postfixpostfix notation|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
Line 45 ⟶ 46:
« 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 »
Line 52 ⟶ 53:
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":
Line 58 ⟶ 59:
« 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.
 
«
Line 72 ⟶ 73:
 
====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
Line 81 ⟶ 82:
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":
 
«
Line 116 ⟶ 117:
 
====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":
 
«
Line 131 ⟶ 132:
 
====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
Line 159 ⟶ 160:
 
== Notes ==
:1.{{note|rpl_acronym_note_1}} "RPL" is derived from '''Reverse Polish Lisp''' according to its original developers,<ref name="Wickes_1988"/><ref name="Wickes_1991"/><ref name="Schoorl_2000"/><ref name="FAQ48"/><ref name="Nelson_2012"/><ref name="Jedrzejowicz_1996"/> while for a short time in 1987 HP marketing attempted to coin the [[backronym]] '''ROM-based Procedural Language''' for it.<ref name="HPJ38"/><ref name="Jedrzejowicz_1996"/><ref name="HP_2007"/> In addition, the RPL initials are sometimes incorrectly interpreted as Reverse Polish Logic or [[Reverse Polish Language]].<ref>{{cite web |url=https://www.hpcalc.org/hp48/docs/hpedia/ |title=HPedia: The HP Calculator Encyclopedia |author-last1=Rechlin |author-first1=Eric |author-last2=Marangon |author-first2=Carlos |website=www.hpcalc.org |access-date=2020-04-20}}</ref>
|first1=Eric |last2=Marangon |first2=Carlos |website=www.hpcalc.org |access-date=April 20, 2020}}</ref>
 
==References==
{{Reflist|refs=
<ref name="Joy_2020">{{cite web |url=https://www.hpmuseum.org/forum/showthread.php?mode=linear&tid=15509&pid=135732 |title=The Joy of Programming? |publisher=Museum of HP Calculators |date=2020 |archive-url=https://web.archive.org/web/20211203131528/https://www.hpmuseum.org/forum/showthread.php?mode=linear&tid=15509&pid=135732 |archive-date=2021-12-03}}</ref>
<ref name="Urroz_2000">{{cite book |author-first=Gilberto E. |author-last=Urroz |title=Programming the HP 49 G Calculator in User RPL Language |date=2000 |url=https://h30434.www3.hp.com/psg/attachments/psg/palm-webossoftware/252122/1/hp49g04.pdf |archive-url=https://web.archive.org/web/20221031143355/https://h30434.www3.hp.com/psg/attachments/psg/palm-webossoftware/252122/1/hp49g04.pdf |archive-date=2022-10-31}}</ref>
<ref name="RPL_2023">{{cite web |url=https://www.hpmuseum.org/rpl.htm |title=RPL |publisher=Museum of HP Calculators |archive-url=https://web.archive.org/web/20230820203818/https://www.hpmuseum.org/rpl.htm |archive-date=2023-08-20}}</ref>
<ref name="RPL_2003">{{cite web |url=https://archived.hpcalc.org/museumforum/thread-35921.html |title=RPN/RPL — What? |date=2003 |publisher=Museum of HP Calculators |archive-url=https://web.archive.org/web/20230820204017/https://archived.hpcalc.org/museumforum/thread-35921.html |archive-date=2023-08-20}}</ref>
<ref name="HP_4">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{{dead link|date=April 2018 |bot=InternetArchiveBot|fix-attempted=yes}}</ref>
<ref name="HP_7">http://www.calculatrices-hp.com/index.php?page=emulateurs<!-- https://web.archive.org/web/20170917223308/http://www.calculatrices-hp.com/index.php?page=emulateurs --></ref>
<ref name="HP_5">{{cite web |url=http://www.hpmuseum.org/forum/thread-4405-post-39600.html |title=Emulator of HP 50g with #2.16 ROM}}</ref>
<ref name="HP_6">http://www.calculatrices-hp.com/uploads/emulateurs/HP50gVirtualCalculatorSetup_3_1_30.zip<!-- https://web.archive.org/web/20170917095533/http://www.calculatrices-hp.com/uploads/emulateurs/HP50gVirtualCalculatorSetup_3_1_30.zip --></ref>
<ref name="HPJ38">{{cite journal |title=Computation for Handheld Calculators |author-last=Patton |author-first=Charles M. |journal=[[Hewlett-Packard Journal]] |publisher=[[Hewlett-Packard Company]] |___location=Palo Alto, California, USA |date=August 1987 |volume=38 |issue=8 |pages=21–25 |url=http://www.hpl.hp.com/hpjournal/pdfs/IssuePDFs/1987-08.pdf |access-date=2015-09-12}}</ref>
<ref name="Wickes_1988">{{cite conference |title=RPL: A Mathematical<!-- also seen as: "Mathematics". Check actual publication's cover. --> Control Language |author-last=Wickes |author-first=William C. |editor-first=Lawrence P. |editor-last=Forsely |date=1988-10-01 |orig-date=14–18 June 1988 |conference=Proceedings of the 1988 Rochester Forth Conference: Programming Environments |volume=8 |publisher=Institute for Applied Forth Research, Inc., [[University of Rochester]] |___location=Rochester, New York, USA |isbn=978-0-91459308-9 |oclc=839704944 <!-- |doi=10.5555/534949--> |pages=27–32 |quote=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 (programming language)|Forth]] with the functional approach of [[Lisp (programming language)|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: [https://web.archive.org/web/20230328115142/https://www.hpcalc.org/details/1743][https://web.archive.org/web/20220419184811/https://www.hpcalc.org/hp48/docs/programming/rplman.zip])</ref>