Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,26 +1,5 @@
|
|||
<?php
|
||||
function Y($f) {
|
||||
$g = create_function('$w', '$f = '.var_export($f,true).';
|
||||
return $f(create_function(\'\', \'$w = \'.var_export($w,true).\';
|
||||
return call_user_func_array($w($w), func_get_args());
|
||||
\'));
|
||||
');
|
||||
return $g($g);
|
||||
return function() use($f) {
|
||||
return call_user_func_array($f(Y($f)), func_get_args());
|
||||
};
|
||||
}
|
||||
|
||||
function almost_fib($f) {
|
||||
return create_function('$i', '$f = '.var_export($f,true).';
|
||||
return ($i <= 1) ? $i : ($f($i-1) + $f($i-2));
|
||||
');
|
||||
};
|
||||
$fibonacci = Y('almost_fib');
|
||||
echo $fibonacci(10), "\n";
|
||||
|
||||
function almost_fac($f) {
|
||||
return create_function('$i', '$f = '.var_export($f,true).';
|
||||
return ($i <= 1) ? 1 : ($f($i - 1) * $i);
|
||||
');
|
||||
};
|
||||
$factorial = Y('almost_fac');
|
||||
echo $factorial(10), "\n";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,26 @@
|
|||
<?php
|
||||
function pseudoY($f) {
|
||||
$g = function($w) use ($f) {
|
||||
return $f->bindTo(function() use ($w) {
|
||||
return call_user_func_array($w($w), func_get_args());
|
||||
});
|
||||
};
|
||||
return $g($g);
|
||||
function Y($f) {
|
||||
$g = create_function('$w', '$f = '.var_export($f,true).';
|
||||
return $f(create_function(\'\', \'$w = \'.var_export($w,true).\';
|
||||
return call_user_func_array($w($w), func_get_args());
|
||||
\'));
|
||||
');
|
||||
return $g($g);
|
||||
}
|
||||
|
||||
$factorial = pseudoY(function($n) {
|
||||
return $n > 1 ? $n * $this($n - 1) : 1;
|
||||
});
|
||||
echo $factorial(10), "\n";
|
||||
|
||||
$fibonacci = pseudoY(function($n) {
|
||||
return $n > 1 ? $this($n - 1) + $this($n - 2) : $n;
|
||||
});
|
||||
function almost_fib($f) {
|
||||
return create_function('$i', '$f = '.var_export($f,true).';
|
||||
return ($i <= 1) ? $i : ($f($i-1) + $f($i-2));
|
||||
');
|
||||
};
|
||||
$fibonacci = Y('almost_fib');
|
||||
echo $fibonacci(10), "\n";
|
||||
|
||||
function almost_fac($f) {
|
||||
return create_function('$i', '$f = '.var_export($f,true).';
|
||||
return ($i <= 1) ? 1 : ($f($i - 1) * $i);
|
||||
');
|
||||
};
|
||||
$factorial = Y('almost_fac');
|
||||
echo $factorial(10), "\n";
|
||||
?>
|
||||
|
|
|
|||
20
Task/Y-combinator/PHP/y-combinator-4.php
Normal file
20
Task/Y-combinator/PHP/y-combinator-4.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
function pseudoY($f) {
|
||||
$g = function($w) use ($f) {
|
||||
return $f->bindTo(function() use ($w) {
|
||||
return call_user_func_array($w($w), func_get_args());
|
||||
});
|
||||
};
|
||||
return $g($g);
|
||||
}
|
||||
|
||||
$factorial = pseudoY(function($n) {
|
||||
return $n > 1 ? $n * $this($n - 1) : 1;
|
||||
});
|
||||
echo $factorial(10), "\n";
|
||||
|
||||
$fibonacci = pseudoY(function($n) {
|
||||
return $n > 1 ? $this($n - 1) + $this($n - 2) : $n;
|
||||
});
|
||||
echo $fibonacci(10), "\n";
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue