From c7f94dd886a72493abbe778ef650ec3b39c96d84 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 22 Dec 2022 11:08:16 +0100 Subject: [PATCH] Examples dir added. --- examples/map.aocla | 17 +++++++++++++++++ examples/rec-for.aocla | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 examples/map.aocla create mode 100644 examples/rec-for.aocla 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