mirror of
https://github.com/antirez/aocla
synced 2024-12-27 09:58:32 +01:00
Examples dir added.
This commit is contained in:
parent
083858ae4c
commit
c7f94dd886
2 changed files with 27 additions and 0 deletions
17
examples/map.aocla
Normal file
17
examples/map.aocla
Normal 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
10
examples/rec-for.aocla
Normal 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
|
Loading…
Reference in a new issue