Examples dir added.

This commit is contained in:
antirez 2022-12-22 11:08:16 +01:00
parent 083858ae4c
commit c7f94dd886
2 changed files with 27 additions and 0 deletions

17
examples/map.aocla Normal file
View file

@ -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

10
examples/rec-for.aocla Normal file
View file

@ -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