Created
December 12, 2009 04:06
-
-
Save clairvy/254725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| zero = | |
| 1 = | |
| ジャッジメントですわ! | |
| 2 = | |
| ジャッジメントですわ! | |
| ジャッジメントですわ! | |
| 1 + 2 = | |
| ジャッジメントですわ! | |
| ジャッジメントですわ! | |
| ジャッジメントですわ! | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| php church.txt > out.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment