Last active
December 11, 2025 20:36
-
-
Save kenwebb/50573ad10d0e0e2ef8b78ec2d55979cf to your computer and use it in GitHub Desktop.
Search - lambda calculus calculator javascript
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
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Thu Dec 11 2025 15:35:34 GMT-0500 (Eastern Standard Time)--> | |
| <XholonWorkbook> | |
| <Notes><![CDATA[ | |
| Xholon | |
| ------ | |
| Title: Search - lambda calculus calculator javascript | |
| Description: | |
| Url: http://www.primordion.com/Xholon/gwt/ | |
| InternalName: 50573ad10d0e0e2ef8b78ec2d55979cf | |
| Keywords: | |
| My Notes | |
| -------- | |
| 2025 Dec 6 | |
| I searched for the following with DuckDuckGo: | |
| lambda calculus calculator javascript | |
| It provided a bunch of interesting looking hits, which I will explore in this workbook. | |
| to test this workbook, with the code in ref[1]: | |
| http://127.0.0.1:8080/XholonLambdaCalc.html?app=Search+-+lambda+calculus+calculator+javascript&src=lstr&gui=clsc | |
| http://127.0.0.1:8080/XholonLambdaCalc.html?app=50573ad10d0e0e2ef8b78ec2d55979cf&src=gist&gui=clsc | |
| TODO: | |
| https://primordion.com/XholonLambdaCalc.html?app=50573ad10d0e0e2ef8b78ec2d55979cf&src=gist&gui=clsc | |
| ### References | |
| (1) https://github.com/VictorTaelin/lambda-calculus | |
| A simple, clean and fast implementation of the λ-calculus on JavaScript. | |
| It has zero dependencies and only 2.65KB gzipped. | |
| It evaluates terms very efficiently by using native JS functions, which is possible thanks to a clever compile/readback algorithm based on JS semantics. | |
| It includes the most relevant IO formats - bruijn-indices, binary, base64 and the usual "Wikipedia syntax" - so you can easily export to/from other tools. | |
| You can also convert native JS functions to terms and back. | |
| npm install lambda-calculus | |
| ) https://github.com/VictorTaelin/lambda-calculus/issues/1 | |
| a cleaner implementation | |
| KSW - I am not using this | |
| (2) https://github.com/gmfc/lambda-calculus-js | |
| ) https://github.com/gmfc/lambda-calculus-js/tree/main | |
| Lambda Calculus with JavaScript | |
| This repository is dedicated to demonstrating the principles of lambda calculus using JavaScript. | |
| a collection of simple lambda calculus stuff as javascript functions | |
| similar to stuff I have done while learning | |
| useful | |
| (3) https://iwilare.com/lambda-js/ | |
| A minimal JavaScript interpreter for λ‑calculus in less than 60 characters. | |
| (4) https://m1el.github.io/smallest-lambda-eval/ | |
| The smallest lambda interpreter in JavaScript | |
| uses De Bruijn indices | |
| worth taking a closer look at sometime | |
| (5) https://tromp.github.io/cl/Binary_lambda_calculus.html | |
| Binary Lambda Calculus | |
| Binary lambda calculus (BLC) is a minimal, pure functional programming language invented by John Tromp in 2004,1 | |
| based on a binary encoding of the untyped lambda calculus in De Bruijn index notation. | |
| KSW interesting | |
| (6) https://medium.com/@axdemelas/lambda-calculus-with-javascript-897f7e81f259 | |
| Lambda Calculus with JavaScript | |
| An introduction to the roots of functional programming | |
| Alexandre Demelas | |
| Oct 1, 2017 | |
| The objective of this article is to present the main concepts of Lambda Calculus with the aid of JavaScript syntax (ES2015), | |
| showing its influence in modern languages and its importance for the future of programming. | |
| (7) https://sshwy.github.io/lamcalc/en/playground.html | |
| λ-Calculus Online Playground | |
| Try writing your lambda expression! We've defined some basic expressions for you: | |
| - unclear what this is about | |
| (8) https://lambda-calculus-interpreter.vercel.app/ | |
| parses, shows tree | |
| (9) https://www.cl.cam.ac.uk/~rmk35/lambda_calculus/lambda_calculus.html#org98242d7 | |
| Lambda-Calculus Evaluator | |
| - hard to know if this would be useful for me ? | |
| (10) https://lambdacalc.dev/ | |
| - might be useful | |
| (11) https://plato.stanford.edu/entries/lambda-calculus/ | |
| comprehensive | |
| includes a section on Combinatory logic | |
| Applications in the semantics of natural language, thanks to developments by Montague and other linguists, helped to ‘spread the word’ about the subject. | |
| Since then the λ-calculus enjoys a respectable place in mathematical logic, computer science, linguistics (see, e.g., Heim and Kratzer 1998), and kindred fields. | |
| - see ref[14] below | |
| (12) http://lambdacalculator.com/ | |
| - old, http only | |
| The Lambda Calculator | |
| For students and teachers of natural language semantics. | |
| By Lucas Champollion, Josh Tauberer, Maribel Romero, Dylan Bumford, Alex Warstadt, Anna Alsop, Raef Khan, and Nigel Flower | |
| The Lambda Calculator is an interactive, graphical application to help students of natural language semantics practice derivations in the typed lambda calculus. | |
| It is designed for both students and teachers, with modules for online classroom instruction, graded homework assignments, and self-guided practice. | |
| The primary function is to assist in the computation of natural language denotations up a syntactic tree in the style of Heim & Kratzer (1998). | |
| To this end, the program detects common errors and attempts to provide intelligent feedback to the student user and a record of performance for the instructor. | |
| (13) https://github.com/nyusemantics/LambdaCalculatorPublic | |
| ) https://github.com/nyusemantics/LambdaCalculatorPublic/wiki/Documentation | |
| public version of ref[12] | |
| (14) https://en.wikipedia.org/wiki/Montague_grammar | |
| Montague grammar is an approach to natural language semantics, named after American logician Richard Montague. | |
| The Montague grammar is based on mathematical logic, especially higher-order predicate logic and lambda calculus, | |
| and makes use of the notions of intensional logic, via Kripke models. | |
| Montague pioneered this approach in the 1960s and early 1970s. | |
| (15) https://theory.stanford.edu/~blynn/lambda/ | |
| Lambda Calculus | |
| lots of topics, a parser, etc. | |
| (16) https://lambster.dev/ | |
| Lambster | |
| A lambda calculus interpreter | |
| ]]></Notes> | |
| <_-.XholonClass> | |
| <PhysicalSystem/> | |
| <Block/> | |
| <Lam/> | |
| <!-- examples from Greg Michaelson book --> | |
| <GMich superClass="Script"/> | |
| <GMich2 superClass="Script"/> | |
| <GMich3 superClass="Script"/> | |
| <FunctionTester/> | |
| </_-.XholonClass> | |
| <xholonClassDetails> | |
| <GMich><Color>orange</Color></GMich> | |
| <Avatar><Color>red</Color></Avatar> | |
| <GMich2> | |
| <DefaultContent><![CDATA[ | |
| var me, beh = { | |
| postConfigure: function() { | |
| me = this.cnode; | |
| const lam = $wnd.xh.lam; | |
| var funk = lam.toFunction(lam.reduce(lam.fromString(me.expr))); | |
| console.log(me.name(), me.expr, funk(33)(77)); // ccc:gMich2 (λa.λb.a) 33 | |
| } | |
| } | |
| //# sourceURL=GMich2_ccc.js | |
| ]]></DefaultContent> | |
| <Color>gold</Color> | |
| </GMich2> | |
| <GMich3> | |
| <DefaultContent><![CDATA[ | |
| var me, args, beh = { | |
| postConfigure: function() { | |
| me = this.cnode; | |
| args = me.args.split(",").map((item) => isNaN(item) ? item : Number(item), []); | |
| console.log("args", args); | |
| const lam = $wnd.xh.lam; | |
| /*if (isNaN(Number(args[0]))) { | |
| console.log("GMich3 1"); | |
| var xa = lam.fromString(args[0]); | |
| console.log(xa); | |
| var xb = lam.reduce(xa); | |
| console.log(xb); | |
| var xc = lam.toString(xb); | |
| console.log(xc); | |
| }*/ | |
| var funk = lam.toFunction(lam.reduce(lam.fromString(me.expr))); | |
| console.log(me.name(), me.expr, funk(args[0])(args[1])); | |
| } | |
| } | |
| //# sourceURL=GMich3_ddd.js | |
| ]]></DefaultContent> | |
| <Color>gold</Color> | |
| </GMich3> | |
| </xholonClassDetails> | |
| <PhysicalSystem> | |
| <Block/> | |
| <FunctionTester funk="(a,b) => a + b" args="981,5"/> | |
| <FunctionTester funk="() => $wnd.xh.root().name()" args=""/> | |
| <Lam/> | |
| <GMich roleName="aaa"><![CDATA[ | |
| var beh = {}; | |
| console.log("GMich aaa"); | |
| const lam = $wnd.xh.lam; | |
| console.log(lam.toString(lam.reduce(lam.fromString("(λa.λb.b)")))); | |
| var second = lam.toFunction(lam.reduce(lam.fromString("(λa.λb.b)"))); | |
| console.log(second); | |
| console.log(second(4)(5)); // 5 | |
| //# sourceURL=GMich_aaa.js | |
| ]]></GMich> | |
| <GMich roleName="bbb"><![CDATA[ | |
| var beh = {}; | |
| console.log("GMich bbb"); | |
| const lam = $wnd.xh.lam; | |
| console.log(lam.toString(lam.reduce(lam.fromString("(λa.λb.a)")))); | |
| var first = lam.toFunction(lam.reduce(lam.fromString("(λa.λb.a)"))); | |
| console.log(first); | |
| console.log(first(4)(5)); // 4 | |
| //# sourceURL=GMich_bbb.js | |
| ]]></GMich> | |
| <GMich roleName="ccc" expr="(λa.λb.λc.a)" args="123,14,98"><![CDATA[ | |
| var me, args, beh = { | |
| postConfigure: function() { | |
| me = this.cnode; | |
| args = me.args.split(",").map((item) => Number(item), []); | |
| var numa = args[0]; | |
| var numb = args[1]; | |
| const lam = $wnd.xh.lam; | |
| var funk = lam.toFunction(lam.reduce(lam.fromString(me.expr))); | |
| console.log(me.name(), me.expr, funk(numa)(numb)(args[2])); // ccc:gMich_50 (λa.λb.λc.a) 123 | |
| } | |
| } | |
| //# sourceURL=GMich_ccc.js | |
| ]]></GMich> | |
| <GMich2 expr="(λa.λb.a)"/> | |
| <GMich2 expr="(λa.λb.b)"/> | |
| <!--<GMich3 expr="(λa.λb.(a b))" args="x => x+3,210"/>--> <!-- Uncaught TypeError: a is not a function --> | |
| <!--<GMich3 expr="(λa.λb.(a b))" args="λx.x+3,210"/>--> <!-- NO --> | |
| </PhysicalSystem> | |
| <Blockbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
| // test of code in ref[1] this works! | |
| const lam = $wnd.xh.lam; | |
| console.log(lam.toString(lam.reduce(lam.fromString("(λa.λb.(a (a b)) λa.λb.(a (a b)))")))); // a.b.(a (a (a (a b)))) | |
| const funk = lam.toFunction(lam.reduce(lam.fromString("(λa.λb.(a (a b)) λa.λb.(a (a b)))"))); | |
| console.log(funk); | |
| console.log(funk(x => x+1)(5)); // 9 | |
| $wnd.xh.root().println(funk(x => x+1)(5)); // 9 | |
| //# sourceURL=Blockbehavior.js | |
| ]]></Blockbehavior> | |
| <Lambehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
| var me, lam, funk, beh = { | |
| postConfigure: function() { | |
| me = this.cnode.parent(); | |
| lam = $wnd.xh.lam; | |
| funk = lam.toFunction(lam.reduce(lam.fromString("(λa.λb.(a (a b)) λa.λb.(a (a b)))"))); | |
| }, | |
| act: function() { | |
| me.println(funk(x => x+3)(30)); // 42 | |
| me.println(funk(new Function("return (x) => x+3"))()(31)); // 34 | |
| } | |
| } | |
| //# sourceURL=Lambehavior.js | |
| ]]></Lambehavior> | |
| <FunctionTesterbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
| console.log("FunctionTesterbehavior"); | |
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function | |
| // testing Function | |
| const sum = Function("a", "b", "return a + b"); | |
| console.log(sum(2, 6)); | |
| // Expected output: 8 YES | |
| const plus1 = Function("x", "return x + 1"); | |
| console.log(plus1(88)); // 89 YES | |
| const findLargestNumber = new Function( | |
| "function findLargestNumber (arr) { return Math.max(...arr) }; return findLargestNumber", | |
| ); | |
| // call the function | |
| console.log(findLargestNumber.call({}).call({}, [2, 4, 1, 8, 5])); | |
| const funky = new Function("const funky = (x) => x + 111; return funky",)(); // YES | |
| const funky2 = new Function("const f = function(x) {return x + 222}; return f"); // YES | |
| console.log(funky(3333)); | |
| console.log(funky2.call()(3333)); | |
| // this works! | |
| // Observe that new Function is called. This is so we can call the function we created directly afterwards | |
| const sumOfArray = new Function("const sumArray = (arr) => arr.reduce((previousValue, currentValue) => previousValue + currentValue); return sumArray",)(); | |
| // call the function | |
| console.log(sumOfArray([1, 2, 3, 4])); // 10 | |
| /* | |
| console.log(this); | |
| console.log(this.parent()); | |
| console.log(this.parent().funk); | |
| if (this.parent().funk) { | |
| console.log("this.parent().funk", this.parent().funk); | |
| const fstr = `const f = ${this.parent().funk}; return f`; | |
| console.log(fstr); | |
| const funkey = new Function(fstr)(); // YES | |
| console.log(funkey(876,1)); // 877 | |
| } | |
| */ | |
| //console.log(new Function(`const f = ${this.parent().funk}; return f`)()(981,5)); // 986 or chameleon_0 | |
| //console.log(new Function(`return ${this.parent().funk};`)()(982,7)); // 989 or chameleon_0 | |
| const args = this.parent().args.split(",").map((item) => isNaN(item) ? item : Number(item), []); | |
| console.log(new Function(`const f = ${this.parent().funk}; return f`)()(...args)); // 986 or chameleon_0 | |
| //# sourceURL=FunctionTesterbehavior.js | |
| ]]></FunctionTesterbehavior> | |
| <SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
| <svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
| <g> | |
| <title>Block</title> | |
| <rect id="PhysicalSystem/Block" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
| <g> | |
| <title>Lam</title> | |
| <rect id="PhysicalSystem/Lam" fill="#6AB06A" height="50" width="10" x="80" y="0"/> | |
| </g> | |
| </g> | |
| </svg> | |
| ]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient> | |
| </XholonWorkbook> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment