file: job.t package: muf status: alpha
Given a block of 2N items, loops N times,
with the designated variables k and v
set successively to
each sequential pair of values in the block. Changing the
k and v variables will
change the corresponding elements of the block:
Stack:
6 seq[
Stack: [ 0 1 2 3 4 |
|forPairs k v do{ v 2 * -> v }
Stack: [ 0 2 2 6 4 10 |
The optional third argument will iterate through the block indices used:
Stack: [ 0 2 4 6 8 |
|forPairs k v i do{ [ "blk[%d] is %d\n" i k | ]print , }
blk[0] is 0
blk[2] is 4
blk[4] is 8
Stack: [ 0 2 4 6 8 |
Note: The body of a |forPairs should not change the size
of the block.
Note: The body of a |forPairs 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.