Php and Ycombinators
I'm vaguely interested in learning Php and functional programming
So I decided to implement a ycombinator powered exponential function in Php 5.3
Obscure geekiness, Ho!
Now I just have to understand how it works in detail.
So I decided to implement a ycombinator powered exponential function in Php 5.3
Obscure geekiness, Ho!
#!/bin/php
<?php
$expo = function($recurse){
return function($n) use ($recurse) {
if ($n == 0)
return 1;
else
return $n * $recurse($n - 1);
};};
$y = function ($builder)
{
return call_user_func( function($f){ return $f($f);} ,function($f) use ($builder)
{
return $builder(function($x) use ($f)
{
return call_user_func($f($f), $x);
});
}
);
};
echo call_user_func($y($expo), 5);
?>Now I just have to understand how it works in detail.