RosettaCodeData/Task/Y-combinator/M2000-Interpreter/y-combinator-1.m2000
2023-07-01 13:44:08 -04:00

14 lines
529 B
Text

Module Ycombinator {
\\ y() return value. no use of closure
y=lambda (g, x)->g(g, x)
Print y(lambda (g, n as decimal)->if(n=0->1, n*g(g, n-1)), 10)=3628800 ' true
Print y(lambda (g, n)->if(n<=1->n,g(g, n-1)+g(g, n-2)), 10)=55 ' true
\\ Using closure in y, y() return function
y=lambda (g)->lambda g (x) -> g(g, x)
fact=y((lambda (g, n as decimal)-> if(n=0->1, n*g(g, n-1))))
Print fact(6)=720, fact(24)=620448401733239439360000@
fib=y(lambda (g, n)->if(n<=1->n, g(g, n-1)+g(g, n-2)))
Print fib(10)=55
}
Ycombinator