Go to the first, previous, next, last section, table of contents.


|for v i do{ ... }

Function: |for var i do{ ... }
file: job.t
package: muf
status: alpha

Given a block of N items, loops N times, with the designated variable set successively to each item in the block. Changing the variable will change the corresponding element of the block:

Stack:
5 seq[
Stack: [ 0 1 2 3 4 |
|for v do{ v 2 * -> v }
Stack: [ 0 2 4 6 8 |

The optional second argument will iterate through the block indices:

Stack: [ 0 2 4 6 8 |
|for v i do{ [ "blk[%d] is %d\n" i v | ]print , }
blk[0] is 0
blk[1] is 2
blk[2] is 4
blk[3] is 6
blk[4] is 8
Stack: [ 0 2 4 6 8 |

Note: The body of a |for should not change the size of the block.

Note: The body of a |for may accumulate results on top of the iterated block. This is not generally recommended, but occasionally very useful. See the implementations of map* in `10-C-lists.muf'. Such accumulation is liable to confuse the arity-deduction code: You will likely need to include a '!' in your arity declaration for the function.


Go to the first, previous, next, last section, table of contents.