diff --git a/examples/map.aocla b/examples/map.aocla new file mode 100644 index 0000000..2e79079 --- /dev/null +++ b/examples/map.aocla @@ -0,0 +1,17 @@ +// This is an implementation of map. There is already one inside +// Aocla, but this will redefine it. + +[(l f) // list and function to apply + $l len (e) // Get list len in "e" + 0 (j) // j is our current index + [] // We will populate this empty list + [$j $e <] [ + $l $j get@ + $f eval + swap -> + $j 1 + (j) + ] while +] 'map def + +[1 2 3] [dup *] map +print diff --git a/examples/rec-for.aocla b/examples/rec-for.aocla new file mode 100644 index 0000000..fdd6edb --- /dev/null +++ b/examples/rec-for.aocla @@ -0,0 +1,10 @@ +// For loop implemented with recursion + +[(x y f) + [$x $y <] [ + $x $f eval + $x 1 + $y $f count + ] if +] 'count def + +0 15 [print "\n" print] count