Y combinator: Difference between revisions
→{{header|SuperCollider}}: clarify why we need z to make the call lazy
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|SuperCollider}}: clarify why we need z to make the call lazy) |
||
Line 5,115:
=={{header|SuperCollider}}==
The direct implementation will not work, because SuperCollider evaluates x.(x) before calling f.
<syntaxhighlight lang="supercollider">
y = { |f| { |x| f.(x.(x)) }.({ |x| f.(x.(x)) }) };
</syntaxhighlight>
For lazy evaluation, this call needs to be postponed by passing a function to f that makes this call (this is what is called the z-combinator):
<syntaxhighlight lang="supercollider">// z-combinator
z = { |f| { |x| f.({ |args| x.(x).(args) }) }.({ |x| f.({ |args| x.(x).(args) }) }) };
// this can be also factored differently
(
{ |
▲ f.({ |args| y.(y).(args) })
)
};
)
// the same in a
(
|