September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View 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