Jump to content

Y combinator: Difference between revisions

1,180 bytes added ,  2 years ago
Added Quackery.
m (→‎{{header|Phix}}: syntax coloured)
(Added Quackery.)
Line 4,641:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
</lang>
 
=={{header|Quackery}}==
 
From the Wikipedia article [[wp:Fixed-point combinator#Implementation_in_other_languages|Fixed-point combinator]]:
 
:The Y combinator is a particular implementation of a fixed-point combinator in lambda calculus. Its structure is determined by the limitations of lambda calculus. It is not necessary or helpful to use this structure in implementing the fixed-point combinator in other languages.
 
<code>recursive</code> is a stateless fixed-point combinator which takes a stateless nest (named or nameless) and returns a recursive version of the nest.
 
As per the task it is used here to compute factorial and Fibonacci numbers.
 
<lang Quackery> [ ' stack nested nested
' share nested join
swap nested join
dup dup 0 peek put ] is recursive ( x --> x )
 
[ over 2 < iff
[ 2drop 1 ] done
dip [ dup 1 - ] do * ] is factorial ( n x --> n )
 
[ over 2 < iff drop done
swap 1 - tuck 1 -
over do dip do + ] is fibonacci ( n x --> n )
 
say "8 factorial = " 8 ' factorial recursive do echo cr
say "8 fibonacci = " 8 ' fibonacci recursive do echo cr</lang>
 
{{out}}
 
<pre>8 factorial = 40320
8 fibonacci = 21
</pre>
 
 
=={{header|R}}==
1,496

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.