RPL+ Quick Reference

 

An RPL+ program is enclosed in ≪ and ≫ characters. The simplest program is:


“Functions”, “commands”, “operators”–built-in or user-provided–all mean the same. The word command is mostly used here, and encompasses them all.


Commands and data must be separated by space characters. Basic notation is post-fix, that is operands appear before operators (e.g., π sin). There’s also support for in-fix notation (e.g., sin(π)) (see below).


RPL+ has imperative and functional language elements.


(Imperative) Control structures direct the flow of execution: if-conditional, for-loop, while-loop, do-loop


(Functional) Programs are data and can be passed as arguments and manipulated before evaluation. Functional composition can be achieved through the use of Program Fragments, easily manipulatable arrays and strings that can contain data and commands, and are evaluable. Higher-level functions can be written and currying is possible.


An implied stack provides the mechanism for argument passing. A program can consume any number of inputs and produce any number of outputs via the stack. Neither inputs nor outputs need declaration.


Various kinds of data types exist: numbers, complex numbers, fractions, continued fractions, algebraic expressions, arrays (comprising vectors, matrices, lists, and hash-tables (dictionaries)), strings, images, etc. There’s no full object-orientation, but there is a polymorphism of functions/operators: a function/operator will take varying effect depending on the kind of object it’s invoked on.


Data types are extensible (but need to be written in JavaScript). New functions indistinguishable from built-in functions can be injected (using JavaScript) and blended into the namespace of global function collections, enlarging the environment in which an RPL+ program runs, reflecting the engine’s “ROM-less” character. (That is, new global, object-specific commands may be created. Existing commands may be re-interpreted.)


Named local variables exist and are created via assignment at any time, with no declarative overhead. They can hold any data type. Global variables can also be utilized (via reference by name) and created and assigned (via standard calculator commands) any data type.


Array accessors exist. Circular arrays and hash-tables are supported.


Automatic array processing exists and permits any single-valued function to be invoked on any kind of array. Additional explicit array processing functions exist: map, fold (reduce), filter, select, find, doUntil, and various others. Most of these take Program Fragments as arguments.


Algebraic expressions exist as an evaluable data type that interfaces with (local and global) variables, and also as immediate algebraic expressions, in-fix entities that will be evaluated as soon as encountered.


There’s a level of support for name spaces via a special folder syntax.


RPL+ can call JavaScript and vice versa. There’s no declarative overhead (and no speed penalty).


RPL+ is fully backward compatible to RPL, the language.

Basics

(c) 2012 Naive Design. All rights reserved.

pdf (1/28/12)http://naivedesign.com/docs/ND1_Reference_RPL+_QuickRef.pdf

if-conditional:


IF condition THEN doThis END

or

IF condition THEN doThis ELSE doThat END


doThis: any number of commands

doThat: any number of commands


condition: any number of commands that result in a boolean (true or false) or number (0 false; not 0 true)



for-loop:


start end FOR variable doThis NEXT

or

start end FOR variable doThis increment STEP

or

start end START doThis NEXT

or

start end START doThis increment STEP


start, end: numerical values

variable: name of a loop variable

increment: any positive or negative nonzero number

doThis: any number of commands


Special commands BREAK, CONTINUE, IFTB (if-then-break), IFTC (if-then-continue) may appear in the doThis part of a for-loop. These prematurely exit the loop and skip to the next iteration, respectively. The IF variations take a condition code and do so conditionally.



do-conditional loop:


DO doThis UNTIL condition END


doThis: any number of commands

condition: any number of commands that result in a boolean (true or false) or number (0 false; not 0 true)



while-conditional loop:


WHILE condition REPEAT doThis END


doThis: any number of commands

condition: any number of commands that result in a boolean (true or false) or number (0 false; not 0 true)

Control Structures

creation/assignment:


=name

or

=:name


name: any name

Assigns or reassign the top-of-stack item to a local variable named name.

In the =: variation, the top-of-stack item is not consumed.



arithmetic update:


=+name, =-name, =*name, =/name

or

=:+name, =:-name, =:*name, =:/name


name: any name

Assigns or reassign the top-of-stack item to a local variable named name.

In the =: variations, the top-of-stack item is not consumed.



auto-increment/-decrement:


++name, --name


name: any name

Increments, decrements by one the given variable.



array access:


arr[expr], =arr[expr]

or

arr[expr:0], =arr[expr:0]


arr: name of a local array variable

Reads or write into the array at an index given by evaluating the algebraic expression between brackets.

Indexing is one-based. (That is, a[1] is the first element in a.)

In the :0 variation, indexing is zero-based. (That is, a[0] is the first element in a.)


If you specify an index beyond the bounds of an array, it will be mapped back into the bounded range with a modulus operation. That is, you get automatic circular buffers.

  An index smaller than the base index (0 or 1) will address the array from the end to the front. That is, when using 1-based addressing, 0 will address the last element. When using 0-based addressing, -1 will be the last element.



zero-based indexing:


0[]


This special instruction selects zero-based indexing by default. To revert individual array access to one-based, append :1 to expr, when doing normal array access.



hash-table/dictionary enabler:


any[]


This special instruction enables any numerical index, or string, or other object, to be used as array index, and transforms arrays into hash-tables/dictionaries. Far-spaced numerical indices can be used to implement sparse arrays.


Local Variables