{"id":19958681,"url":"https://github.com/ioannad/lambda","last_synced_at":"2026-03-04T07:31:50.923Z","repository":{"id":184424513,"uuid":"194171347","full_name":"ioannad/lambda","owner":"ioannad","description":"A mirror of https://gitlab.common-lisp.net/idimitriou/lambda   A toy interpreter and compiler of the untyped λ calculus, written in common lisp.","archived":false,"fork":false,"pushed_at":"2022-02-07T23:45:01.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-01T16:15:44.661Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Common Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ioannad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-06-27T22:33:36.000Z","updated_at":"2020-10-01T17:03:48.000Z","dependencies_parsed_at":"2023-07-28T23:16:21.071Z","dependency_job_id":null,"html_url":"https://github.com/ioannad/lambda","commit_stats":null,"previous_names":["ioannad/lambda"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ioannad/lambda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioannad%2Flambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioannad%2Flambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioannad%2Flambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioannad%2Flambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ioannad","download_url":"https://codeload.github.com/ioannad/lambda/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioannad%2Flambda/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30075427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T05:31:57.858Z","status":"ssl_error","status_checked_at":"2026-03-04T05:31:38.462Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-11-13T01:44:10.231Z","updated_at":"2026-03-04T07:31:50.902Z","avatar_url":"https://github.com/ioannad.png","language":"Common Lisp","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lambda\n\n#### A toy interpreter and compiler of the untyped λ calculus, written in common lisp.\n\nA toy compiler of the untyped lambda calculus into common lisp (so far), written in common lisp, with an interpreter and a user interface (UI).\n\nThe UI includes a viewer of all available transformations of a user-input λ term, as well as two simple REPLs.\nThe viewer can also evaluate terms before listing their different representations, and therefore is the recommended part of the UI (Church arithmetic support TBA).\n\n##### Goal\n\nThe goal of this project is to compile the untyped λ calculus and extensions thereof into several targets, such as a stack machine (WebAssembly in mind), and some assembly languages. \n\nFor learning and understanding compilers, therefore I write most of it by hand. Written in common lisp because I am most comfortable with this language.\n\n## Try it!\n\nRequirements\n\n- Common Lisp REPL (SBCL and CCL tested) with Quicklisp installed\n\nClone this repository to a directory where Quicklisp can find it, for example in `quicklisp/local-projects/` or in whatever `(:tree ...)` you have in `~/.config/common-lisp/repos.conf`.\n\nIn your Common Lisp REPL evaluate:\n   \n```\n(ql:quickload \"lambda\")\n(in-package :lambda.ui)\n(main)\n```\n   \nYou'll be prompted: \n\n```\nInput which UI to use:\n  3  for the transformation viewer\n  2  for the church REPL\n  1  for the base REPL\n  0  to exit\nAnything else will return help instructions.\n```\n\nThe UI help instructions include the BNF of the standard syntax of this λ calculus, and a short description of each menu options. Each UI mode starts with help instructions specific to the UI mode, examples of usage, and the set of self encoded primitives, such as `:ID :TRUE :FALSE :S :AND :OR :IF :Y :OMEGA`, which you can use when entering a λ term.\n\n#### Examples of λ terms, without and with primitives, and of reductions.\n\nNote that only single variable abstractions are allowed.\n\nWithout primitives:\n\n```\nd\n(x y)\n(λ a (λ b (a b))\n```\n\nWith primitives:\n\n```\n((:or :true) a)\n(((:if :false) a ) b)\n```\n\nIn the UI's \"base REPL\", the above evaluate to `:true` and `b`, respectively.\n\n## Implementation features\n  - A User Interface (UI) in the package `:lambda.ui` (call `(main)`) using self-encoded primitives (encoded as λ terms). \n    The UI includes:\n\t+ A transformation viewer: Input a λ TERM and see its available representations (see next list item). Evaluate the TERM before returning the different representations with =:eval TERM=. In the TERM you can use the same primitives as the `λ.base` REPL below.\n\t+ Two simple Read Eval Print Loops (REPLs) for this λ calculus:\n          * `λ.base` allows you to use the following symbols as self-encoded primitives: `:ID :TRUE :FALSE :S :AND :OR :IF :Y :OMEGA`\n          * `λ.church` allows you to use base, as well as numbers in your statements, and the following symbols as primitives for numeric functions:\n            `:A+ :A* :Aexp :Azero? :A+1 :A-1 :A-factorial`, for plus, times, exponent, zero test, successor, predecessor, and factorial.\n\n  - Showcases representations of lambda terms in my quest to understand compilers.\n    So far, showcased representations of lambda terms are the following.\n      + The standard, single variable binding, parenthesised lambda terms as quoted common-lisp lists, for example, `'(^ x (x y))`.\n      + De Bruijn representation (locally nameless for open terms), the example becomes `'(^ (0 y))`.\n      + A common lisp representation, the example becomes `'(lambda (x) (funcall x y))`.\n      + An implementation of Tromp's\n        * combinatorial logic representation in the form of SKI-calculus (towards a stack machine - WebAssembly),\n        * and his binary representation.\n      + TBA: Implementation of Mogensen's continuation passing style self encoding of lambda calculus (Mogensen-Scott encoding).\n      + I provide transformations between defined representations.\n  - Lazy, normal order, and applicative order reducers, with respective steppers and self-evaluation loop catchers.\n  - A λ calculus interpreter in common-lisp and a compiler to common lisp lambda abstractions.\n  - Compiler transformations and simplifications are currently only β-reducing in normal order with loop-catching and maximum allowed steps, closing possibly open terms, full renaming of bound variables, then switching to common-lisp syntax and returning the resulting common-lisp closure.\n  \n  For the base of this implementation I just followed Barendrecht and Barendsen's 1994 book \"Introduction to Lambda Calculus\" [BarBar84]. TBA representations come with respective papers (see references below), which I am currently implementing.\n\n#### Tested\n   \n   By adding a catch-loop stepper-based reducer of the standard representation, I have been able to use cl-quickcheck on arbitrary generated terms, and\n   quickcheck also examples, theorems, and lemmas from [BarBar84].\n   \n   Extensive manually written tests are performed as well.\n   \n   Run all tests for CCL and SBCL by loading `run-all-tests.lisp`, or for a particular common lisp implementation from the command line for example as `ccl -b -l run-all-tests.lisp`.\n   \n#### Documented\n\nI used the principle of literal programming, with comments in plain text format. The beginning of each file should be informative of the file contents.\n   \n\n# TODO\n\nImmediate TODO goals, in my priority order, starting from highest priority.\n-  Implement Tromp's cross interpreter for SKI-terms.\n-  Add transformation of SKI-calculus terms to WebAssembly.\n-  Implement more encodings or/and replace them with primitives of a target language (e.g. WebAssembly).\n-  Find a nicer way around printing keywords with their dots (print related functions in ui.lisp are messy!)\n-  Implement UI for steppers.\n-  Find a faster encoding for natural numbers or integers, or/and get common lisp (or other target languages, such as the above mentioned stack machine)\n-  Compile to my computer's assembly (with the help of disassembly).\n-  Unify the 3 UI \"modes\" into one big REPL. Low priority because it's probably not that relevant to the main goals of this project.\n\n# References\n \nIn several places in documentation and in comments, I refer to the following publications, in LaTeX bibtex-style alpha.\n\n- [Bar84] **The Lambda Calculus: Its Syntax and Semantics**, H.P. Barendregt, *Elsevier (1984)*\n- [BarBar84] **Introduction to lambda calculus**, H.P. Barendregt and E.Barendsen, *Nieuw archief voor wisenkunde 4, 337-372 (1984)*\n- [Tro18] **Functional Bits : Lambda Calculus based Algorithmic Information Theory**, J. Tromp, *\u003chttps://tromp.github.io/cl/LC.pdf\u003e (2018)*\n- [Mog94] **Efficient Self-Interpretation in Lambda Calculus**, T. Mogensen, *Journal of Functional Programming 2, (1994)*\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioannad%2Flambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fioannad%2Flambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioannad%2Flambda/lists"}