Skip to content

Instantly share code, notes, and snippets.

@clairvy
Created December 12, 2009 04:06
Show Gist options
  • Select an option

  • Save clairvy/254725 to your computer and use it in GitHub Desktop.

Select an option

Save clairvy/254725 to your computer and use it in GitHub Desktop.
<?php
$f = function () {
// チャーチ数の定義
$zero = function ($f) {
return function ($x) use ($f) {
return $x;
};
};
$inc = function ($n) {
return function($f) use ($n) {
return function ($x) use ($f, $n) {
$org = $n($f);
$org_v = $org($x);
return $f($org_v);
};
};
};
$add = function($n, $m) {
return function($f) use ($n, $m) {
return function($x) use ($f, $n, $m) {
$org_n = $n($f);
$org_n_v = $org_n($x);
$org_m = $m($f);
return $org_m($org_n_v);
};
};
};
// 補助関数
$print = function ($n) {
$itr = function ($x) {
return ($x . "ジャッジメントですわ!\n");
};
$new_func = $n($itr);
echo $new_func("");
};
echo "zero = \n";
$print($zero);
echo "\n";
$one = $inc($zero);
echo "1 = \n";
$print($one);
echo "\n";
$two = $inc($one);
echo "2 = \n";
$print($two);
echo "\n";
echo "1 + 2 = \n";
$tmp = $add($one, $two);
$print($tmp);
echo "\n";
};
$f();
?>
zero =
1 =
ジャッジメントですわ!
2 =
ジャッジメントですわ!
ジャッジメントですわ!
1 + 2 =
ジャッジメントですわ!
ジャッジメントですわ!
ジャッジメントですわ!
php church.txt > out.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment