Jump to content

Y combinator: Difference between revisions

m
(→‎{{header|Elm}}: complete the solution with both Z and Y combinators and their use...)
m (→‎{{header|Lambdatalk}}: improving code)
Line 3,566:
 
=={{header|Lambdatalk}}==
Tested in http://epsilonwikilambdaway.free.fr/lambdawaylambdawalks/?view=Ycombinator
 
<lang Scheme>
1) defining the Ycombinator
{def Y {lambda {:f} {:f :f}}}
{lambda {:f :n}
{:f :f :n}}}
 
2) defining non recursive functions
Line 3,590 ⟶ 3,588:
 
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
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.