{"id":44657063,"url":"https://github.com/dallaylaen/ski-interpreter","last_synced_at":"2026-02-14T22:19:44.810Z","repository":{"id":248917288,"uuid":"830151392","full_name":"dallaylaen/ski-interpreter","owner":"dallaylaen","description":"Combinatory logic and lambda calculus interpreter in plain JS. Supports SKI, BCKW, Church numerals, defining one's own terms, λ ↔ SK conversions, and more. An HTML playground and quest page included.","archived":false,"fork":false,"pushed_at":"2026-02-08T00:08:59.000Z","size":1917,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-08T07:58:47.848Z","etag":null,"topics":["church-numerals","combinators","combinatory-logic","functional-programming","lambda-calculus","playground","tutorials"],"latest_commit_sha":null,"homepage":"https://dallaylaen.github.io/ski-interpreter/","language":"JavaScript","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/dallaylaen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-17T17:38:16.000Z","updated_at":"2026-02-08T00:09:02.000Z","dependencies_parsed_at":"2024-08-04T09:25:15.095Z","dependency_job_id":"8369d5db-b0aa-44dd-b5ce-6aff3a080ff1","html_url":"https://github.com/dallaylaen/ski-interpreter","commit_stats":null,"previous_names":["dallaylaen/ski-interpreter"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/dallaylaen/ski-interpreter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fski-interpreter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fski-interpreter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fski-interpreter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fski-interpreter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dallaylaen","download_url":"https://codeload.github.com/dallaylaen/ski-interpreter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fski-interpreter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29458453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T21:29:27.764Z","status":"ssl_error","status_checked_at":"2026-02-14T21:28:11.111Z","response_time":53,"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":["church-numerals","combinators","combinatory-logic","functional-programming","lambda-calculus","playground","tutorials"],"created_at":"2026-02-14T22:19:42.251Z","updated_at":"2026-02-14T22:19:44.790Z","avatar_url":"https://github.com/dallaylaen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Kombinator Interpreter\n\nThis package contains a\n[combinatory logic](https://en.wikipedia.org/wiki/Combinatory_logic)\nand [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus)\nparser and interpreter focused on traceability and inspectability.\n\nIt is written in plain JavaScript (with bolted on TypeScript support)\nand can be used in Node.js or in the browser.\n\n# Features:\n\n* SKI and BCKW combinators\n* Lambda expressions\n* Church numerals\n* Defining new terms\n* \u0026lambda; \u0026lrarr; SKI conversion\n* Comparison of expressions\n* Includes a class for building and executing test cases for combinators\n\n# Syntax\n\n* Uppercase terms are always single characters and may be lumped together;\n* Lowercase alphanumeric terms may have multiple letters and must therefore be separated by spaces;\n* Whole non-negative numbers are interpreted as Church numerals, e.g. `5 x y` evaluates to `x(x(x(x(x y))))`. They must also be space-separated from other terms;\n* `x y z` is the same as `(x y) z` or `x(y)(z)` but **not** `x (y z)`;\n* Unknown terms are assumed to be free variables;\n* Lambda terms are written as `x-\u003ey-\u003ez-\u003eexpr`, which is equivalent to\n`x-\u003e(y-\u003e(z-\u003eexpr))` (aka right associative). Free variables in a lambda expression ~~stay in Vegas~~ are isolated from terms with the same name outside it;\n* X = y z defines a new term.\n\n## Starting combinators:\n\n* \u003ccode\u003eI x \u0026mapsto; x\u003c/code\u003e _// identity_;\n* \u003ccode\u003eK x y \u0026mapsto; x\u003c/code\u003e _//constant_;\n* \u003ccode\u003eS x y z \u0026mapsto; x z (y z)\u003c/code\u003e _// fusion_;\n* \u003ccode\u003eB x y z \u0026mapsto; x (y z)\u003c/code\u003e _// composition_;\n* \u003ccode\u003eC x y z \u0026mapsto; x z y\u003c/code\u003e _// swapping_;\n* \u003ccode\u003eW x y \u0026mapsto; x y y\u003c/code\u003e _//duplication_;\n\nThe special combinator `+` will increment Church numerals, if they happen to come after it:\n\n* `+ 0` // 1\n* `2 + 3` // -\u003e `+(+(3))` -\u003e `+(4)` -\u003e `5`\n\nThe `term + 0` idiom may be used to convert\nnumbers obtained via computation (e.g. factorials)\nback to human readable form.\n\n# Execution strategy\n\nApplications and native terms use normal strategy, i.e. the first term in the tree\nthat has enough arguments is executed and the step ends there.\n\nLambda terms are lazy, i.e. the body is not touched until\nall free variables are bound.\n\n# Playground\n\n* [Interactive interpreter](https://dallaylaen.github.io/ski-interpreter/)\n\n  * all of the above features (except comparison and JS-native terms) in your browser\n  * expressions have permalinks\n  * can configure verbosity and execution speed\n\n* [Quests](https://dallaylaen.github.io/ski-interpreter/quest.html)\n\nThis page contains small tasks of increasing complexity.\nEach task requires the user to build a combinator with specific properties.\n\n# CLI\n\nREPL comes with the package as [bin/ski.js](bin/ski.js).\n\n# Installation\n\n```bash\nnpm install @dallaylaen/ski-interpreter\n```\n\n# Usage\n\n## A minimal example\n\n```javascript\n#!node\n\nconst { SKI } = require('@dallaylaen/ski-interpreter');\n\n// Create a parser instance\nconst ski = new SKI();\n\n// Parse an expression\nconst expr = ski.parse(process.argv[2]);\n\n// Evaluate it step by step\nfor (const step of expr.walk({max: 100})) {\n  console.log(`[${step.steps}] ${step.expr}`);\n}\n```\n\n## Main features\n\n```javascript\nconst { SKI } = require('@dallaylaen/ski-interpreter');\nconst ski = new SKI();\n\nconst expr = ski.parse(src);\n\n// evaluating expressions\nconst next = expr.step(); // { steps: 1, expr: '...' }\nconst final = expr.run({max: 1000}); // { steps: 42, expr: '...' }\nconst iterator = expr.walk();\n\n// applying expressions\nconst result = expr.run({max: 1000}, arg1, arg2 ...);\n// same sa\nexpr.apply(arg1).apply(arg2).run();\n// or simply\nexpr.apply(arg1, arg2).run();\n\n// equality check\nski.parse('x-\u003ey-\u003ex').equals(ski.parse('a-\u003eb-\u003ea')); // true\nski.parse('S').equals(SKI.S); // true\nski.parse('x').apply(ski.parse('y')).equals(ski.parse('x y')); // also true\n\n// defining new terms\nski.add('T', 'CI'); // T x y = C I x y = I y x = y\nski.add('M', 'x-\u003ex x'); // M x = x x\n\n// also with native JavaScript implementations:\nski.add('V', x=\u003ey=\u003ef=\u003ef.apply(x, y), 'pair constructor');\n\nski.getTerms(); // all of the above as an object\n\n// converting lambda expressions to SKI\nconst lambdaExpr = ski.parse('x-\u003ey-\u003ex y');\nconst steps = [...lambdaExpr.toSKI()];\n// steps[steps.length - 1].expr only contains S, K, I, and free variables, if any\n\n// converting SKI expressions to lambda\nconst skiExpr = ski.parse('S K K');\nconst lambdaSteps = [...skiExpr.toLambda()];\n// lambdaSteps[lambdaSteps.length - 1].expr only contains lambda abstractions and applications\n```\n\n## Fancy formatting\n\nThe `format` methods of the `Expr` class supports\na number of options, see [the source code](src/expr.js) for details.\n\n## Variable scoping\n\nBy default, parsed free variables are global and equal to any other variable with the same name.\nVariables inside lambdas are local to said lambda and will not be equal to anything except themselves.\n\nA special `scope` argument may be given to parse to limit the scope. It can be any object.\n\n```javascript\nconst scope1 = {};\nconst scope2 = {};\nconst expr1 = ski.parse('x y', {scope: scope1});\nconst expr2 = ski.parse('x y', {scope: scope2}); // not equal\nconst expr3 = ski.parse('x y'); // equal to neither\nconst expr4 = ski.parse('x', {scope: scope1}).apply(ski.parse('y', {scope: scope1})); // equal to expr1\n```\n\nVariables can also be created using magic `SKI.vars(scope)` method:\n\n```javascript\nconst scope = {};\nconst {x, y, z} = SKI.vars(scope); // no need to specify names\n```\n\n## Querying the expressions\n\nExpressions are trees, so they can be traversed.\n\n```javascript\nexpr.any(e =\u003e e.equals(SKI.S)); // true if any subexpression is S\n\nexpr.traverse(e =\u003e e.equals(SKI.I) ? SKI.S.apply(SKI.K, SKI.K) : null);\n// replaces all I's with S K K\n// here a returned `Expr` object replaces the subexpression,\n// whereas `null` means \"leave it alone and descend if possible\"\n```\n\n## Test cases\n\nThe `Quest` class may be used to build and execute test cases for combinators.\n\n```javascript\nconst { Quest } = require('@dallaylaen/ski-interpreter');\n\nconst q = new Quest({\n    name: 'Test combinator T',\n    description: 'T x y should equal y x',\n    input: 'T',\n    cases: [\n        ['T x y', 'y x'],\n    ],\n});\n\nq.check('CI'); // pass\nq.check('a-\u003eb-\u003eb a'); // ditto\nq.check('K'); // fail\nq.check('K(K(y x))') // nope! the variable scopes won't match\n```\n\nSee [quest page data](docs/quest-data/) for more examples.\n\n# Thanks\n\n* [@ivanaxe](https://github.com/ivanaxe) for luring me into [icfpc 2011](http://icfpc2011.blogspot.com/2011/06/task-description-contest-starts-now.html) where I was introduced to combinators.\n* [@akuklev](https://github.com/akuklev) for explaining functional programming to me so many times that I actually got some idea.\n\n# Prior art and inspiration\n\n* \"To Mock The Mockingbird\" by Raymond Smulian.\n* [combinator birds](https://www.angelfire.com/tx4/cus/combinator/birds.html) by [Chris Rathman](https://www.angelfire.com/tx4/cus/index.html)\n* [Fun with combinators](https://doisinkidney.com/posts/2020-10-17-ski.html) by [@oisdk](https://github.com/oisdk)\n* [Conbinatris](https://dirk.rave.org/combinatris/) by Dirk van Deun\n\n# License and copyright\n\nThis software is free and available under the MIT license.\n\n\u0026copy; Konstantin Uvarin 2024\u0026ndash;2026\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdallaylaen%2Fski-interpreter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdallaylaen%2Fski-interpreter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdallaylaen%2Fski-interpreter/lists"}