aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2024-06-16 07:49:37 -0400
committerClyne Sullivan <clyne@bitgloo.com>2024-06-16 07:49:37 -0400
commitd832f781dbc57b9a6223150db07343ea990fb611 (patch)
tree44fdbd5e4a39d15992297305dccf3136f3d6bcf2
parentc278aa4e696359764848edd66c6bb457e248d43e (diff)
finish fibonacci example
-rw-r--r--test.fp26
1 files changed, 19 insertions, 7 deletions
diff --git a/test.fp b/test.fp
index 498a3eb..e4aba6c 100644
--- 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
@@ -24,13 +24,25 @@
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
)