==== DOLIST ====
----
Do a procedure with elements of lists
----
^ __Input Stack__ ^^^^^ ^ __Output Stack__ ^
| **L1** | **...** | **Ln** | **In** | **Pexec** | **→** | **Lresults** |
| **L1** | **...** | **Ln** | **In** | **Nexec** | **→** | **Lresults** |
| //Level n+2// | //...// | //Level 3// | //Level 2// | //Level 1// | //→// | //Level 1// |
{{page>manual:chapter6:aux:legend&nofooter&noeditbtn&inline}}
| **Keyword type** | [[manual:chapter5:basics#commands|Command]] ||
| **Parallel list processing capabilities** | [[manual:chapter5:listproc#group-2commands-that-must-use-dolist-to-parallel-process|Group 2]] | //Commands that must use //''[[manual:chapter6:lists:cmd_cmddolist|DOLIST]]''// to parallel process// |
| **Affected by flags** | //None// ||
----
The ''DOLIST'' command ''[[manual:chapter6:operators:cmd_ovr_eval|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 ''[[manual:chapter6:operators:cmd_ovr_eval|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 [[manual:chapter5:listproc#group-8multiple-result-commands|here]] can help disentangling the results.
----
''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 before ''DOLIST'' is launched can be reached or altered.
----
**__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 }
…………………………………………………………………………………………………………
----
{{page>manual:chapter6:lists&nofooter&noeditbtn&inline}}