2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
12
Task/Y-combinator/Forth/y-combinator-1.fth
Normal file
12
Task/Y-combinator/Forth/y-combinator-1.fth
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
\ Address of an xt.
|
||||
variable 'xt
|
||||
\ Make room for an xt.
|
||||
: xt, ( -- ) here 'xt ! 1 cells allot ;
|
||||
\ Store xt.
|
||||
: !xt ( xt -- ) 'xt @ ! ;
|
||||
\ Compile fetching the xt.
|
||||
: @xt, ( -- ) 'xt @ postpone literal postpone @ ;
|
||||
\ Compile the Y combinator.
|
||||
: y, ( xt1 -- xt2 ) >r :noname @xt, r> compile, postpone ; ;
|
||||
\ Make a new instance of the Y combinator.
|
||||
: y ( xt1 -- xt2 ) xt, y, dup !xt ;
|
||||
7
Task/Y-combinator/Forth/y-combinator-2.fth
Normal file
7
Task/Y-combinator/Forth/y-combinator-2.fth
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
\ Factorial
|
||||
10 :noname ( u1 xt -- u2 ) over ?dup if 1- swap execute * else 2drop 1 then ;
|
||||
y execute . 3628800 ok
|
||||
|
||||
\ Fibonacci
|
||||
10 :noname ( u1 xt -- u2 ) over 2 < if drop else >r 1- dup r@ execute swap 1- r> execute + then ;
|
||||
y execute . 55 ok
|
||||
Loading…
Add table
Add a link
Reference in a new issue