You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
941 B
Plaintext

4 months ago
(
; core utilities
($x ^x ^x) $dup
($_) $drop
($x $y ^x ^y) $swap
($a $b $c ^b ^a ^c) $rot
(sub) $-
(0 swap - -) $+
(()) $nil
(nil eq) $null?
($x x) $force
(10 emit) $cr
(print) $print
4 months ago
; if-stmt
($c $t $f c ^f ^t rot cswap $_ force) $if
($f $t $c $fn ^f ^t ^c fn) $endif
; range
($self $start $end
^if (^start ^end eq)
^nil
(^start ^end ^start 1 + self swap cons)
endif
) $range
; map [$fn $list -> $out-list]
($self $fn $list
^if (^list null?)
^nil
(^list car fn ^list cdr ^fn self swap cons)
4 months ago
endif
) $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
4 months ago
10 1 range
^fibonacci map
^print each
4 months ago
)