aocla/examples/foreach.aocla
2023-01-30 11:45:55 +01:00

14 lines
456 B
Text

// This is a commented version of the implementation of 'foreach' inside
// the standard library.
[(l f) // list and function to call with each element.
$l len (e) // Get list len in "e"
0 (j) // j is our current index
[$j $e <] [
$l $j get@ // Get list[j]
$f upeval // We want to evaluate in the context of the caller
$j 1 + (j) // Go to the next index
] while
] 'foreach def
[1 2 3] [printnl] foreach