Skip to content

Commit 25b01dd

Browse files
committed
Demand one argument and define -d and -s
1 parent b4d8356 commit 25b01dd

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
all: compile.js
22
npm install
3-
node lambda debug.mlc >|output.tmp
4-
tail output.tmp
5-
time -p node lambda
3+
node lambda -d debug.mlc
4+
time -p node lambda fact.mlc
65

76
compile.js: grammar.jison
87
npm install [email protected]
@@ -11,5 +10,5 @@ compile.js: grammar.jison
1110
mv $@.tmp $@
1211

1312
clean:
14-
-rm -f *.tmp stats.json
13+
-rm -f *.tmp
1514
-rm -fr node_modules

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
This package implements the pure untyped lambda calculus using
2-
interaction nets, providing both CLI and API described below.
2+
interaction nets, providing both CLI and API.
33

44
# CLI
55

66
This package provides a `lambda` command with the following interface:
77

88
```
9-
Usage: lambda [file]
9+
Usage: lambda [options] <file.mlc>
1010
1111
Options:
12+
--debug, -d Enable step-by-step evaluation [boolean]
13+
--stats, -s Save statistics to a file [string]
1214
--help, -h Show help [boolean]
1315
--version, -v Show version number [boolean]
1416
@@ -24,7 +26,7 @@ The last term in the input is the term whose normal form is to be found.
2426
For developing and testing purposes, the package also exports
2527
two additional functions `.prepare(term)` and `.debug()`.
2628
The `.debug()` function applies a single reduction step to
27-
the interaction net compiled by the previous `.prepare(src, fmt)`
29+
the interaction net compiled by the previous `.prepare()`
2830
call and returns a human-readable string representation of
2931
the current interaction net state.
3032

lambda.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@ var lambda = require(".");
44
var yargs = require("yargs");
55
var fs = require("fs");
66

7+
var opts = {
8+
debug: {
9+
alias: "d",
10+
desc: "Enable step-by-step evaluation",
11+
boolean: true
12+
},
13+
stats: {
14+
alias: "s",
15+
desc: "Save statistics to a file",
16+
string: true
17+
}
18+
};
19+
720
var argv = yargs
8-
.usage("Usage: $0 [file]")
21+
.usage("Usage: $0 [options] <file.mlc>")
22+
.options(opts)
23+
.demandCommand(1)
924
.help()
1025
.alias("help", "h")
1126
.version()
@@ -14,23 +29,23 @@ var argv = yargs
1429
.wrap(70)
1530
.argv;
1631

17-
var file = argv._[0];
32+
var input = fs.readFileSync(argv._[0], "utf8");
1833

19-
if (file) {
20-
var input = fs.readFileSync(file, "utf8");
34+
if (argv.debug) {
2135
var eqn;
2236

2337
lambda.prepare(input);
2438

2539
while (eqn = lambda.debug1())
2640
console.log(eqn);
2741
} else {
28-
var output = lambda(lambda.example);
42+
var output = lambda(input);
2943
var stats = JSON.stringify(output.stats, null, "\t");
3044

3145
console.log(output.term);
3246
console.info("%s(%s)", output.total, output.beta);
3347
console.log(output.nf);
3448

35-
fs.writeFileSync("stats.json", stats + "\n");
49+
if (argv.stats)
50+
fs.writeFileSync(argv.stats, stats + "\n");
3651
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"repository": "codedot/lambda",
55
"name": "@alexo/lambda",
66
"bin": "./lambda.js",
7-
"version": "0.0.1",
7+
"version": "0.0.2",
88
"license": "MIT",
99
"dependencies": {
1010
"inet-lib": "0.2.0",

0 commit comments

Comments
 (0)