Content deleted Content added
→PHP Example: new section |
|||
Line 202:
:::I was merely acting on an observation that c.e. (or r.e.) is not necessarily infinite. I think your explanation should be added into the page, maybe as ref remark, replacing the "cn" tag. [[User:WillNess|WillNess]] ([[User talk:WillNess|talk]]) 17:20, 9 December 2011 (UTC)
== PHP Example ==
Here's a tested PHP implementation for the Y Combinator function:
<source lang=php>
function Y(callable $f)
{
$funcA = function ($x) use ($f)
{
return $f(function ($v) use ($x)
{
$funcB = ($x($x));
return $funcB($v);
});
};
return $funcA($funcA);
}
</source>
And the factorial example applied to it:
<source lang=php>
$factorial = Y(
function ($fac)
{
return function ($n) use ($fac)
{
if ($n === 0) {
return 1;
} else {
return $n * $fac($n - 1);
}
};
}
);
$result = $factorial(5); // 120
</source>
[[User:Jazzer7|Jazzer7]] ([[User talk:Jazzer7|talk]]) 06:51, 6 June 2012 (UTC)
|