This commit is contained in:
Lobo 2026-01-21 13:48:20 -03:00
parent 6a9a0cd4e4
commit d359c68c32
16 changed files with 2026 additions and 89 deletions

View file

@ -1,9 +1,25 @@
def fib/aux {
if: dig dup 0 =
[drop drop]
[bury [swap 1 - swap] dip dup [+] dip swap fib/aux]
;
[bury [swap 1 - swap] dip dup [+] dip swap fib/aux];
}
def fib { 0 1 fib/aux }
[ 50 fib ] call .
"50 fib => " type
50 fib .
def times {
if: over 0 =
[drop drop]
[swap over >r >r call r> 1 - r> times];
}
\ We can also calculate the Fibonnaci numbers using the `times' combinator
\ we just implemented:
def fib-iter {
0 1 dig times: [dup [+] dip swap]; drop
}
"50 fib-iter => " type
50 fib-iter .