jambda-calc
raw JSON → 0.6.1 verified Fri May 01 auth: no javascript
jambda-calc (v0.6.1) is a TypeScript library that transpiles JavaScript/TypeScript functions into pure lambda calculus expressions and visualizes them as Tromp diagrams. It supports arithmetic, common operators, conditionals, nested functions, and basic array methods like .filter() and .map(). The library is in active development with a focus on educational and explorative use—ideal for understanding the theoretical underpinnings of computation. It provides a CLI tool and programmatic API, with TypeScript definitions included. Notable limitations include no support for string operations, recursion, async functions, imports, or advanced member functions. The project aims to handle entire JS projects in the future.
Common errors
error Error: Unsupported operation: Math.cos ↓
cause Member functions other than .filter() and .map() are not implemented.
fix
Replace Math.cos() with a manual computation or avoid such functions.
error Error: Number literal out of range: 150 ↓
cause Only numbers from -100 to 100 are supported.
fix
Reduce the number to within [-100, 100] or restructure the logic.
error Error: Cannot find module 'jambda-calc' ↓
cause Package not installed in the project or not on the path.
fix
Run
pnpm install jambda-calc (or npm/yarn) in the project directory. Verify node_modules and package.json. Warnings
breaking Unsupported operations (string, recursion, async, imports) will throw an error or produce incorrect results. ↓
fix Ensure input code only uses supported features: arithmetic, boolean/numbers, conditionals, simple functions, .filter(), .map().
gotcha Number literals only supported in range -100 to 100. ↓
fix Use only numbers between -100 and 100; larger numbers will cause errors.
gotcha CLI must be run via pnpm or npx; global install does not expose command. ↓
fix Use `pnpm jambda-calc` or `npx jambda-calc` from project directory.
Install
npm install jambda-calc yarn add jambda-calc pnpm add jambda-calc Imports
- transpile wrong
const transpile = require('jambda-calc').transpile;correctimport { transpile } from 'jambda-calc'; - visualize wrong
import { viz } from 'jambda-calc';correctimport { visualize } from 'jambda-calc'; - jambdaCalc wrong
import jambdaCalc from 'jambda-calc';correctimport { jambdaCalc } from 'jambda-calc';
Quickstart
import { transpile, visualize } from 'jambda-calc';
import * as fs from 'fs';
// Transpile a simple arithmetic function
const jsCode = 'function add(a, b) { return a + b; }';
const lambdaExpr = transpile(jsCode);
console.log('Lambda expression:', lambdaExpr);
// Visualize the expression as Tromp diagram SVG
const svg = visualize(lambdaExpr, { format: 'svg' });
fs.writeFileSync('add-tromp.svg', svg);