Skip to content

Commit 3b7e90d

Browse files
committed
Predefine commonly used combinators
1 parent 0d61f62 commit 3b7e90d

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all: compile.js
22
npm install
33
node lambda -h
4-
node lambda -e "(x, y, z: x z (y z)) hello bye world"
4+
node lambda -ce "S hello bye world"
55
node lambda -d debug.mlc
66
node lambda -pt fact.mlc
77

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This package provides a `lambda` command with the following interface:
99
Usage: lambda [options] (<file> | -e <expr>)
1010
1111
Options:
12+
--comb, -c Predefine commonly used combinators [boolean]
1213
--term, -t Output the term being evaluated [boolean]
1314
--perf, -p Print benchmarks [boolean]
1415
--expr, -e Process the argument as expression [boolean]

helper.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
I = x: x;
2+
K = x, y: x;
3+
S = x, y, z: x z (y z);
4+
T = K;
5+
F = x, y: y;
6+
AND = p, q: p q F;
7+
OR = p, q: p T q;
8+
NOT = p: (a, b: p b a);
9+
C0 = f, x: x;
10+
C1 = f, x: f x;
11+
C2 = f, x: f (f x);
12+
C3 = f, x: f (f (f x));
13+
C4 = f, x: f (f (f (f x)));
14+
C5 = f, x: f (f (f (f (f x))));
15+
C6 = f, x: f (f (f (f (f (f x)))));
16+
C7 = f, x: f (f (f (f (f (f (f x))))));
17+
C8 = f, x: f (f (f (f (f (f (f (f x)))))));
18+
C9 = f, x: f (f (f (f (f (f (f (f (f x))))))));
19+
C10 = f, x: f (f (f (f (f (f (f (f (f (f x)))))))));
20+
SUCC = n: (f, x: f (n f x));
21+
PLUS = m, n: (f, x: m f (n f x));
22+
MULT = m, n: (f: m (n f));
23+
EXP = m, n: n m;
24+
PRED = n: (f, x: n (g, h: h (g f)) (K x) I);
25+
MINUS = m, n: n PRED m;
26+
ZERO = n: n (K F) T;
27+
A = self, f: f (self self f);
28+
Y = A A;

lambda.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
var lambda = require(".");
44
var yargs = require("yargs");
5+
var path = require("path");
56
var fs = require("fs");
67

78
var opts = {
9+
comb: {
10+
alias: "c",
11+
desc: "Predefine commonly used combinators",
12+
boolean: true
13+
},
814
term: {
915
alias: "t",
1016
desc: "Output the term being evaluated",
@@ -44,18 +50,22 @@ var argv = yargs
4450
.wrap(70)
4551
.argv;
4652

53+
var comb = fs.readFileSync(path.join(__dirname, "helper.txt"), "utf8");
4754
var input = argv._[0];
4855

4956
if (!argv.expr)
5057
input = fs.readFileSync(input, "utf8");
5158

59+
if (argv.comb)
60+
input = comb.concat(input);
61+
5262
if (argv.debug) {
5363
var eqn;
5464

5565
lambda.prepare(input);
5666

5767
while (eqn = lambda.debug1())
58-
console.log(eqn);
68+
console.info(eqn);
5969
} else {
6070
var output = lambda(input);
6171
var stats = JSON.stringify(output.stats, null, "\t");

0 commit comments

Comments
 (0)