This is an old revision of the document!
Lists
Lists are ordered collections of objects of any type. Lists are entered as a sequence of objects enclosed in curly braces {
and }
. The syntax rules of each individual object still apply when they are within a list.
Lists can contain any number of items, including none, therefore the empty list { }
is valid and can be used. Items can be repeated within a list, and the order in which items are inserted is preserved unless the order is intentionally changed, for example using the SORT
command.
Operating with Lists
In most cases, commands will accept a list instead of a single argument and will proceed according to the Parallel Processing with Lists section. For example, lists can be used to quickly apply the same operation to more than one value:
2: { 1 2 3 } 1: 1 …………………………………………………………………………………… +
will result in adding 1
to each element on the list: { 2 3 4 }
.
There's operations that are exclusive to lists, for example the command ADD
will concatenate two lists, or append 1 element at the end of the list.
2: { 1 2 3 } 1: 1 …………………………………………………………………………………… ADD
will result in { 1 2 3 1 }
and
2: { 1 2 3 } 1: { 4 5 6 } …………………………………………………………………………………… ADD
will result in { 1 2 3 4 5 6 }
Other common commands that are specific for lists include (look into the command reference for details on specific commands). Operations with Lists
ADD
Synopsis
Concatenate lists and/or elements
Description
The ADD
command concatenates lists or adds an element to a new list. It's not necessary that either the first or the second argument is a list: in this case ADD
will create a new list containing both: in other words, single objects are treated as one-element lists.
Compatibility
ADD
is not fully equivalent to its userRPL counterpart.
In particular:
- in userRPL list concatenation is performed by the
+
operator, whileADD
is the command to parallel process the addition; - in userRPL at least one of the arguments must be a list.
Usage
Input
4: 3: 2: { 1 1 2 3 } 1: { 5 8 13 } ………………………………………………………………………………………………………… ADD
Output
4: 3: 2: 1: { 1 1 2 3 5 8 13 } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
ADDROT
Synopsis
Add elements to a list, keeping only the last N elements
Description
The ADDROT
command adds element to a list just like the command ADD
does, but with a difference: if the list grows larger than Isize elements, the first one gets removed.
Compatibility
ADDROT
is specific to newRPL and has no direct equivalent in userRPL.
Usage
Input
4: 3: { A B C } 2: X 1: 3 ………………………………………………………………………………………………………… ADDROT
Output
4: 3: 2: 1: { B C X } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
DOLIST
Synopsis
Do a procedure with elements of lists
Description
The DOLIST
command EVAL
uates a specified program (or a variable which contains one) to lists of objects.
All lists must be the same length len. The program is executed len times: on the i-th iteration, In objects each taken from the i-th position in each list are entered on the stack in the same order as in their original lists, and the program Pexec is EVAL
uated. The results from each execution are left on the stack.
After the final iteration, any new results are combined into a single list: the UNMIX
program presented here can help disentangling the results.
Compatibility
DOLIST
is not fully equivalent to its userRPL counterpart.
In particular:
- in userRPL the number of arguments can be omitted under certain conditions; in newRPL it must be always specified;
- the program launched by
DOLIST
operates in a protected stack environment: no elements present on the stack beforeDOLIST
is launched can be reached or altered.
Usage
Input
5: { 1 2 3 } 4: { 4 5 6 } 3: { 7 8 9 } 2: 3 1: « + * » ………………………………………………………………………………………………………… DOLIST
Output
4: 3: 2: 1: { 11 26 45 } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
ΔLIST
Synopsis
Return first differences of elements of a list
Description
The ΔLIST
command returns the first differences of the elements in the list Ldata, i.e.:
$$ data_2-data_1 \\
data_3-data_2 \\
data_4-data_3 \\
\ldots $$
The list must contain at least two elements, and the elements themselves must be suitable for mutual subtraction.
Compatibility
ΔLIST
is fully equivalent to its userRPL counterpart.
Usage
Input
4: 3: 2: 1: { 39 18 5 '2*X' 73 } ………………………………………………………………………………………………………… ΔLIST
Output
4: 3: 2: 1: { -21 -13 '2*X-5' '73-2*X' } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
DOSUBS
Synopsis
Do a procedure on a subset of a list
Description
The DOSUBS
command EVAL
uates a specified program (or a variable which contains one) to groups of elements in a list.
The first iteration uses elements 1 through In from the list; the second iteration uses elements 2 through In + 1; and so on. In general, the m-th iteration uses the elements from the list corresponding to positions m through m + In – 1.
During an iteration, the position of the first element used in that iteration is available to the user using the local variable NSUB
, and the number of groups of elements is available using the local variable ENDSUB
.
DOSUBS
is nominally designed for Pexec (or Nexec) requiring In arguments and returning one result.
Compatibility
DOSUBS
is not fully equivalent to its userRPL counterpart.
In particular:
- in userRPL the number of arguments can be omitted under certain conditions; in newRPL it must be always specified;
- in userRPL
NSUB
andENDSUBS
are commands; in newRPL they are local variables; - the program launched by
DOSUBS
operates in a protected stack environment: no elements present on the stack beforeDOSUBS
is launched can be reached or altered.
Usage
Input
{ 1 2 3 4 5 } 2 « → a b « CASE 'NSUB==1' THEN a END 'NSUB==ENDSUB' THEN b END 'a+b' EVAL END » » DOSUBS
Output
4: 3: 2: 1: { 1 5 7 5 } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
LIST→
Synopsis
Split a list into its elements
Description
The LIST→
command takes a list of In and returns each object to a separate level, and returns the total number of objects to stack level 1.
Compatibility
LIST→
is fully equivalent to its userRPL counterpart.
Usage
Input
4: 3: 2: 1: { 1 3 5 } ………………………………………………………………………………………………………… LIST→
Output
4: 1 3: 3 2: 5 1: 3 …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
MAP
Synopsis
Do a procedure on each element of a list, recursively
Description
The MAP
command EVAL
uates a specified program (or a variable which contains one) to a list of objects or values. If one of the objects is a list, MAP
will apply the program recursively to the items in the inner list.
MAP
is nominally designed for Pexec (or Nexec) requiring one argument and returning one result.
Compatibility
MAP
is fully equivalent to its userRPL counterpart.
Usage
Input
4: 3: 2: { 1 2 { X Y } } 1: « 2 * » ………………………………………………………………………………………………………… MAP
Output
4: 3: 2: 1: { 2 4 { 'X*2' 'Y*2' } } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
ΠLIST
Synopsis
Return the product of all elements in a list
Description
The ΠLIST
command returns the product of all the elements in Ldata, i.e.:
$$ \prod_{k=1}^{n}{data_{k}} $$
The list must not be empty and its elements must be suitable for mutual multiplication.
Compatibility
ΠLIST
is not fully equivalent to its userRPL counterpart.
In particular:
- in userRPL the list must contain at least two elements.
Usage
Input
4: 3: 2: 1: { 5 'Z' '8+Y' } ………………………………………………………………………………………………………… ΠLIST
Output
4: 3: 2: 1: '5*Z*(8+Y)' …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
REVLIST
Synopsis
Reverse the order of elements in a list
Description
The REVLIST
command reverses the order of elements in a list. In addition with the SORT
command it can be used to sort a list in descending order.
Compatibility
REVLIST
is fully equivalent to its userRPL counterpart.
Usage
Input
4: 3: 2: 1: { 5 1 4 3.1415 } ………………………………………………………………………………………………………… REVLIST
Output
4: 3: 2: 1: { 3.1415 4 1 5 } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
SEQ
Synopsis
Assemble a list from results of sequential procedure
Stack Diagram
Input Stack | Output Stack | |||||
---|---|---|---|---|---|---|
Pexec | Nindex | Numstart | Numend | Numincr | → | Lresults |
Aexec | Nindex | Numstart | Numend | Numincr | → | Lresults |
Nexec | Nindex | Numstart | Numend | Numincr | → | Lresults |
Level 5 | Level 4 | Level 3 | Level 2 | Level 1 | → | Level 1 |
Description
The SEQ
command returns a list of results generated by repeatedly EVAL
uating a program, a symbolic object or an identifier using Nindex over the range Numstart to Numend, in increments of Numincr.
The action of SEQ
for arbitrary inputs can be predicted exactly from this equivalent program:
Numstart Numend FOR 'Nindex' Pexec EVAL Numincr STEP n → LIST
where n
is the number of new objects left on the stack by the FOR
… STEP
loop. Notice that Nindex becomes a local variable regardless of its original type.
Compatibility
SEQ
is not fully equivalent to its userRPL counterpart.
In particular:
- the program launched by
SEQ
operates in a protected stack environment: no elements present on the stack beforeSEQ
is launched can be reached or altered.
Usage
Input
5: 'n^2' 4: 'n' 3: 1 2: 9 1: 2 ………………………………………………………………………………………………………… SEQ
Output
4: 3: 2: 1: { '1' '9' '25' '49' '81' } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
SORT
Synopsis
Sort elements in a list
Description
The SORT
command uses a variant of the Insertion Sort (namely, the Binary Insertion Sort) to order the elements of a list in ascending order.
All the elements in the list must be of the same type; the comparison between elements is done by the CMP
operator: if the TYPE
of the objects within the list is not supported by CMP
, no error is issued and the original list is left unmodified.
Compatibility
SORT
is not fully equivalent to its userRPL counterpart.
In particular:
- in newRPL strings are not supported (yet).
Usage
Input
4: 3: 2: 1: { 5 1 4 3.1415 } ………………………………………………………………………………………………………… SORT
Output
4: 3: 2: 1: { 1 3.1415 4 5 } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
STREAM
Synopsis
Assemble a list from results of sequential procedure
Description
The STREAM
command moves the first two elements from Ldata onto the stack, EVAL
uating a program or an identifier. Then moves the next element (if any) onto the stack, and EVAL
uates Pexec (or Nexec) again using the previous result and the new element. Repeats this until Ldata is exhausted, and returns the final result.
STREAM
is nominally designed for Pexec (or Nexec) requiring two arguments and returning one result.
Compatibility
STREAM
is not fully equivalent to its userRPL counterpart.
In particular:
- the program launched by
STREAM
operates in a protected stack environment: no elements present on the stack beforeSTREAM
is launched can be reached or altered.
Usage
Input
4: 3: 2: { "A" "B" "C" "D" } 1: « SWAP + » ………………………………………………………………………………………………………… STREAM
Output
4: 3: 2: 1: "DCBA" …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
ΣLIST
Synopsis
Return the sum of all elements in a list
Description
The ΣLIST
command returns the sum of all the elements in Ldata, i.e.:
$$ \sum_{k=1}^{n}{data_{k}} $$
The list must not be empty and its elements must be suitable for mutual addition.
Compatibility
ΣLIST
is not fully equivalent to its userRPL counterpart.
In particular:
- in userRPL the list must contain at least two elements.
Usage
Input
4: 3: 2: 1: { 1 'X' '3*Y' } ………………………………………………………………………………………………………… ΣLIST
Output
4: 3: 2: 1: '1+X+3*Y' …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
→LIST
Synopsis
Assemble a list from its elements
Description
The →LIST
command combines the first In elements on the stack above itself in a list.
Compatibility
→LIST
is fully equivalent to its userRPL counterpart.
Usage
Input
4: '3/8' 3: "This is a string" 2: 'SIN(X)' 1: 2 ………………………………………………………………………………………………………… →LIST
Output
4: 3: 2: '3/8' 1: { "This is a string" 'SIN(X)' } …………………………………………………………………………………………………………
Related Commands
Command | Short Description | |
---|---|---|
→LIST | Assemble a list from its elements | |
LIST→ | Split a list into its elements | |
DOLIST | Do a procedure with elements of lists | CHANGED |
DOSUBS | Do a procedure on a subset of a list | CHANGED |
MAP | Do a procedure on each element of a list, recursively | |
MAPLIST→ | Do a procedure on each element recursively, return individual elements | NEW |
STREAM | Do a procedure on consecutive elements of a list | |
ΔLIST | First differences on the elements of a list | |
ΣLIST | Sum of all elements in a list | CHANGED |
ΠLIST | Product of all elements in a list | CHANGED |
ADD | Concatenate lists and/or elements | CHANGED |
SORT | Sort elements in a list | |
REVLIST | Reverse the order of elements in a list | |
ADDROT | Add elements to a list, keep only the last N elements | NEW |
SEQ | Assemble a list from results of sequential procedure |
→LIST
: Creates a list from loose objects in the stackLIST→
: Split a list into individual objects in the stackSORT
: Sort the elements of a list