From fb0f0b5a2685212cf4ba3de40cb208ed15384591 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 20 Apr 2024 08:51:53 +0100 Subject: Make the example a bit more interesting --- examples/fold.fco | 16 ++++++++++++++-- 1 file 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 -- cgit v1.2.3