September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
16
Task/Y-combinator/Elena/y-combinator.elena
Normal file
16
Task/Y-combinator/Elena/y-combinator.elena
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import extensions.
|
||||
|
||||
singleton YCombinator
|
||||
{
|
||||
fix : func
|
||||
= (:f)[(:x)[ x eval:x ] eval(:g)[ f eval(:x)[(g eval:g) eval:x] ]] eval:func.
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var fib := YCombinator fix(:f)((:i)( (i <= 1) ifTrue:[^i] ifFalse:[^f eval(i-1) + f eval(i-2) ] )).
|
||||
var fact := YCombinator fix(:f)((:i)((i == 0) ifTrue:[^1] ifFalse:[^f eval(i-1) * i] )).
|
||||
|
||||
console printLine("fib(10)=",fib eval(10)).
|
||||
console printLine("fact(10)=",fact eval(10)).
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue