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 |