mirror of
https://github.com/antirez/aocla
synced 2025-01-13 20:01:40 +01:00
Add library procedures: map, foreach, first, rest.
This commit is contained in:
parent
f8d8a629ab
commit
daa29ee819
1 changed files with 11 additions and 0 deletions
11
aocla.c
11
aocla.c
|
@ -1045,7 +1045,18 @@ void loadLibrary(aoclactx *ctx) {
|
|||
addProcString(ctx,"dup","[(x) $x $x]");
|
||||
addProcString(ctx,"swap","[(x y) $y $x]");
|
||||
addProcString(ctx,"drop","[(_)]");
|
||||
|
||||
/* [1 2 3] [dup *] map => [1 4 9] */
|
||||
addProcString(ctx,"map", "[(l f) $l len (e) 0 (j) [] [$j $e <] [ $l $j get@ $f upeval swap -> $j 1 + (j)] while]");
|
||||
|
||||
/* [1 2 3] [printnl] foreach */
|
||||
addProcString(ctx,"foreach"," [(l f) $l len (e) 0 (j) [$j $e <] [$l $j get@ $f upeval $j 1 + (j)] while]");
|
||||
|
||||
/* [1 2 3] first => 1 */
|
||||
addProcString(ctx,"first","[0 get@]");
|
||||
|
||||
/* [1 2 3] rest => [2 3] */
|
||||
addProcString(ctx,"rest","[#t (f) [] (n) [[$f] [#f (f) drop] [$n -> (n)] ifelse] foreach $n]");
|
||||
}
|
||||
|
||||
/* ================================ CLI ===================================== */
|
||||
|
|
Loading…
Reference in a new issue