diff options
author | Juan J. Martinez <jjm@usebox.net> | 2024-04-20 08:51:53 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2024-04-20 08:51:53 +0100 |
commit | fb0f0b5a2685212cf4ba3de40cb208ed15384591 (patch) | |
tree | 938f1fecfd10bbd7f90c9e1b8dcce687187f6064 | |
parent | d17a1e3aa5565963c24e9e0b40ca4548f377a44c (diff) | |
download | funco-fb0f0b5a2685212cf4ba3de40cb208ed15384591.tar.gz funco-fb0f0b5a2685212cf4ba3de40cb208ed15384591.zip |
Make the example a bit more interesting
-rw-r--r-- | examples/fold.fco | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/examples/fold.fco b/examples/fold.fco index ea3f5e4..c9b8e5c 100644 --- a/examples/fold.fco +++ b/examples/fold.fco @@ -6,7 +6,19 @@ def op(acc x) end end -# add odd numbers from 1 to 10 +# generate a list from 1 to n +def range(n) + def genrec(l limit n) + if <(n limit) + @genrec(+(l list(n)) limit +(n 1)) + else + l + end + end + genrec(list() n 0) +end + +# add odd numbers from 0 to 1001 def main() - display(fold(0 op list(1 2 3 4 5 6 7 8 9 10))) + display(fold(0 op range(1001))) end |