September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
42
Task/Y-combinator/Lambdatalk/y-combinator.lambdatalk
Normal file
42
Task/Y-combinator/Lambdatalk/y-combinator.lambdatalk
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
1) defining the Ycombinator
|
||||
{def Y
|
||||
{lambda {:f :n}
|
||||
{:f :f :n}}}
|
||||
|
||||
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
|
||||
|
||||
We could also forget the Ycombinator and names:
|
||||
|
||||
1) fac:
|
||||
{{lambda {:f :n} {:f :f :n}}
|
||||
{lambda {:f :n}
|
||||
{if {= :n 1}
|
||||
then 1
|
||||
else {* :n {:f :f {- :n 1}}}}} 6}
|
||||
-> 720
|
||||
|
||||
2) fibo:
|
||||
{{lambda {:f :n} {:f :f :n}}
|
||||
{{lambda {:f :n}
|
||||
{if {< :n 2} then 1
|
||||
else {+ {:f :f {- :n 1}} {:f :f {- :n 2}}}}}} 8}
|
||||
-> 34
|
||||
Loading…
Add table
Add a link
Reference in a new issue