diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-06-16 07:49:37 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-06-16 07:49:37 -0400 |
commit | d832f781dbc57b9a6223150db07343ea990fb611 (patch) | |
tree | 44fdbd5e4a39d15992297305dccf3136f3d6bcf2 | |
parent | c278aa4e696359764848edd66c6bb457e248d43e (diff) |
finish fibonacci example
-rw-r--r-- | test.fp | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -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 ) |