]> code.bitgloo.com Git - clyne/forspll.git/commitdiff
finish fibonacci example
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 16 Jun 2024 11:49:37 +0000 (07:49 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 16 Jun 2024 11:49:37 +0000 (07:49 -0400)
test.fp

diff --git a/test.fp b/test.fp
index 498a3eb496fd56c1cd53a24732ba53e7829bebd7..e4aba6c29c2ddef56733ac036d08c1209f0eb46e 100644 (file)
--- a/test.fp
+++ b/test.fp
@@ -10,7 +10,7 @@
   (nil eq)            $null?
   ($x x)              $force
   (10 emit)           $cr
-  (dup car swap cdr)  $carcdr
+  (print)             $print
 
   ; if-stmt
   ($c $t $f c ^f ^t rot cswap $_ force) $if
     endif
   ) $range
 
-  ($self $func $list
+  ; map [$fn $list -> $out-list]
+  ($self $fn $list
     ^if (^list null?)
-      nil
-      (^list carcdr swap func ^func self)
+      ^nil
+      (^list car fn ^list cdr ^fn self swap cons)
     endif
-  ) $foreach
+  ) $map
+
+  ; each [$fn $list]
+  ($fn (fn ^nil) map drop) $each
+
+  ; implementation
+  (0 1 ($self $a $b $n
+    ^if (^n 0 eq) (^b) (
+      ^n 1 - ^a ^b + ^b self
+    ) endif
+  ) force) $fibonacci
 
-  58 48 range
-  ^emit foreach cr
+  10 1 range
+  ^fibonacci map
+  ^print each
 )