{"id":13616473,"url":"https://github.com/igorw/lambda-php","last_synced_at":"2025-08-24T06:39:02.361Z","repository":{"id":12518463,"uuid":"15188269","full_name":"igorw/lambda-php","owner":"igorw","description":"Lambda calculus interpreter in PHP.","archived":false,"fork":false,"pushed_at":"2014-05-26T11:01:46.000Z","size":242,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T20:44:59.821Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/igorw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-14T16:05:26.000Z","updated_at":"2024-11-05T09:59:58.000Z","dependencies_parsed_at":"2022-08-31T09:25:17.995Z","dependency_job_id":null,"html_url":"https://github.com/igorw/lambda-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/igorw/lambda-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Flambda-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Flambda-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Flambda-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Flambda-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorw","download_url":"https://codeload.github.com/igorw/lambda-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Flambda-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271809065,"owners_count":24825640,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T20:01:29.010Z","updated_at":"2025-08-24T06:39:02.337Z","avatar_url":"https://github.com/igorw.png","language":"PHP","funding_links":[],"categories":["PHP","杂项","杂项 Miscellaneous","Miscellaneous"],"sub_categories":[],"readme":"# lambda-php\n\n![reduce forever](doc/reduce-forever.png)\n\nLambda calculus interpreter in PHP.\n\n## Lambda calculus\n\nLambda calculus is a very minimal programming language that was invented in\n1936 by Alonzo Church. It is the functional equivalent of the Turing Machine.\n\nLambda calculus has only three concepts: Function definitions, lexically\nscoped variables, function application.\n\nAn example term would be the identity function:\n\n    λx.x\n\nThe first part `λx` defines a function that takes an `x`, the `.` signifies\nthat the part that follows is the function body. The body just returns `x`.\n\nIn PHP, you would write the same thing as follows:\n\n    function ($x) {\n        return $x;\n    }\n\nYou can nest function definitions. Here is a function returning a function:\n\n    λx.λy.x\n\nAnd you can also *apply* a function to an argument, which just means calling\nthe function.\n\n    λf.λg.f g\n\nWhich is the short hand (left-associative) form of writing\n\n    λf.λg.(f g)\n\nNested calls like:\n\n    λf.λg.λh.f g h\n\nAre interpreted as:\n\n    λf.λg.λh.((f g) h)\n\nIf you want to change the grouping to be right-associative, you need to\nexplicitly group them in parentheses:\n\n    λf.λg.λh.(f (g h))\n\nInterestingly, lambda calculus is turing complete. Using just these three\nconcepts you can represent *any* computation.\n\nCheck out the links at the bottom for more details on how to do stuff in\nlambda calculus.\n\n## Interpreter\n\nThis project consists of a lambda calculus expression parser using\n[dissect](https://github.com/jakubledl/dissect), and an *eval-apply*\ninterpreter based on [Matt Might's implementation in\nscheme](http://matt.might.net/articles/implementing-a-programming-language/).\n\nThe interpreter is *call-by-value* which means that recursive calls need to be\nwrapped in a function to prevent them from being evaluated eagerly.\n\nFor examples of how to do numbers (church encoding), booleans, arithmetic,\nboolean logic, looping (recursion), etc. look at `example.php`.\n\n## REPL\n\nThis project ships with a read-eval-print-loop that you can use to evaluate\nlambda calculus expressions:\n\n    $ php repl.php\n\nBy default, it is in *int-mode*, expecting the result of the expression to be\na church-encoded number. Example:\n\n    $ php repl.php\n    i\u003e λf.λx.f (f (f x))\n    3\n\nYou can switch to *bool-mode* by sending the `b` command:\n\n    $ php repl.php\n    i\u003e b\n    b\u003e λx.λy.x\n    true\n\nOr `r` for raw mode:\n\n    $ php repl.php\n    i\u003e r\n    r\u003e λx.x\n    λx.x\n\n## WIP\n\nA few things are still a work in progress:\n\n* **Krivine machine:** This alternate interpreter would allow call-by-need\n  and indexing into de-bruijn indices, which is needed by...\n\n* **Binary lambda calculus:** Allows encoding lambda calculus programs in\n  binary form which produces extremely small programs. This also defines an\n  I/O mechanism.\n\n## References\n\n* [Matt Might: 7 lines of code, 3 minutes](http://matt.might.net/articles/implementing-a-programming-language/)\n* [Tom Stuart: Programming with Nothing](http://codon.com/programming-with-nothing)\n* [Jean-Louis Krivine: A call-by-name lambda-calculus machine](http://www.pps.univ-paris-diderot.fr/~krivine/articles/lazymach.pdf)\n* [Rémi Douence, Pascal Fradet: The Next 700 Krivine Machines](http://pop-art.inrialpes.fr/~fradet/PDFs/HOSC07.pdf)\n* [Xavier Leroy: The Zinc Experiment](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.6772)\n* [John Tromp: Binary Lambda Calculus and Combinatory Logic](http://homepages.cwi.nl/~tromp/cl/LC.pdf)\n* [John Tromp: Binary Lambda Calculus interpreter for IOCCC](http://www.ioccc.org/2012/tromp/hint.html)\n* [Erkki Lindpere: Parsing Lambda Calculus in Scala](http://zeroturnaround.com/rebellabs/parsing-lambda-calculus-in-scala/)\n* [Binary Lambda Calculus in Python](https://github.com/sdiehl/bnlc)\n* [Krivine Machine in Scheme](https://github.com/ympbyc/Carrot)\n* [Algorithmic Information Theory in Haskell](https://github.com/tromp/AIT)\n* [Lambda Calculus - Wikipedia](http://en.wikipedia.org/wiki/Lambda_calculus)\n* [Binary Lambda Calculus - Wikipedia](http://en.wikipedia.org/wiki/Binary_lambda_calculus)\n* [De Bruijn index - Wikipedia](http://en.wikipedia.org/wiki/De_Bruijn_index)\n\n## Thanks to\n\n* [@ympbyc](https://twitter.com/ympbyc)\n* [@smdiehl](https://twitter.com/smdiehl)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorw%2Flambda-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorw%2Flambda-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorw%2Flambda-php/lists"}