aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2024-04-20 08:51:53 +0100
committerJuan J. Martinez <jjm@usebox.net>2024-04-20 08:51:53 +0100
commitfb0f0b5a2685212cf4ba3de40cb208ed15384591 (patch)
tree938f1fecfd10bbd7f90c9e1b8dcce687187f6064 /examples
parentd17a1e3aa5565963c24e9e0b40ca4548f377a44c (diff)
downloadfunco-fb0f0b5a2685212cf4ba3de40cb208ed15384591.tar.gz
funco-fb0f0b5a2685212cf4ba3de40cb208ed15384591.zip
Make the example a bit more interesting
Diffstat (limited to 'examples')
-rw-r--r--examples/fold.fco16
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