23 lines
393 B
Text
23 lines
393 B
Text
1) defining the Ycombinator
|
|
{def Y {lambda {:f} {:f :f}}}
|
|
|
|
2) defining non recursive functions
|
|
2.1) factorial
|
|
{def almost-fac
|
|
{lambda {:f :n}
|
|
{if {= :n 1}
|
|
then 1
|
|
else {* :n {:f :f {- :n 1}}}}}}
|
|
|
|
2.2) fibonacci
|
|
{def almost-fibo
|
|
{lambda {:f :n}
|
|
{if {< :n 2}
|
|
then 1
|
|
else {+ {:f :f {- :n 1}} {:f :f {- :n 2}}}}}}
|
|
|
|
3) testing
|
|
{{Y almost-fac} 6}
|
|
-> 720
|
|
{{Y almost-fibo} 8}
|
|
-> 34
|