Skip to content

Commit 345f5b5

Browse files
author
Johan Wiltink
committed
Y is now a primitive
more debug logging in lc.js remove Y from test sources remove verbosity from test suites
1 parent 34915a5 commit 345f5b5

File tree

10 files changed

+19
-22
lines changed

10 files changed

+19
-22
lines changed

src/lambda-calculus.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ class Tuple {
9595
function Primitive(v) { return new Tuple(new V( "<primitive>" ), new Env([[ "<primitive>" , function*() { while ( true ) yield v; } () ]])); }
9696

9797
const primitives = new Env;
98-
primitives.setThunk( "trace", new Tuple( Primitive( function(v) { console.log(String(v.term)); return v; } ), new Env ) );
99-
100-
const Y = new L("f",new A(new L("x",new A(new V("f"),new A(new V("x"),new V("x")))),new L("x",new A(new V("f"),new A(new V("x"),new V("x"))))));
98+
primitives.setThunk( "trace", new Tuple( Primitive( function(v) { console.info(String(v.term)); return v; } ), new Env ) );
99+
primitives.setThunk( "Y", new Tuple( new L("f",new A(new L("x",new A(new V("f"),new A(new V("x"),new V("x")))),new L("x",new A(new V("f"),new A(new V("x"),new V("x")))))), new Env ) );
101100

102101
function fromInt(n) { return fromIntWith()(n); }
103102

@@ -176,6 +175,7 @@ function parseWith(cfg={}) {
176175
if ( purity === "Let" )
177176
return Array.from(FV).reduce( (tm,nm) => {
178177
if ( env.has(nm) ) {
178+
if ( config.verbosity >= "Verbose" ) console.debug(` using ${ nm } = ${ env.getValue(nm) }`);
179179
tm.env.set( nm, env.get(nm) );
180180
return tm;
181181
} else {
@@ -185,16 +185,17 @@ function parseWith(cfg={}) {
185185
} , new Tuple( term, new Env ) );
186186
else if ( purity==="LetRec" )
187187
return Array.from(FV).reduce( (tm,nm) => {
188-
if ( nm === name )
189-
return tm;
190-
else if ( env.has(nm) ) {
191-
tm.env.set( nm, env.get(nm) );
192-
return tm;
193-
} else {
194-
if ( verbosity >= "Concise" ) console.error(`parse: while defining ${ name } = ${ term }`);
195-
throw new ReferenceError(`undefined free variable ${ nm }`);
196-
}
197-
} , new Tuple( FV.has(name) ? new A(Y,new L(name,term)) : term , new Env ) );
188+
if ( nm === name )
189+
return tm;
190+
else if ( env.has(nm) ) {
191+
if ( config.verbosity >= "Verbose" ) console.debug(` using ${ nm } = ${ env.getValue(nm) }`);
192+
tm.env.set( nm, env.get(nm) );
193+
return tm;
194+
} else {
195+
if ( verbosity >= "Concise" ) console.error(`parse: while defining ${ name } = ${ term }`);
196+
throw new ReferenceError(`undefined free variable ${ nm }`);
197+
}
198+
} , new Tuple( FV.has(name) ? new A(env.getValue("Y"),new L(name,term)) : term , new Env ) );
198199
else if ( purity==="PureLC" )
199200
if ( FV.size ) {
200201
if ( verbosity >= "Concise" ) console.error(`parse: while defining ${ name } = ${ term }`);
@@ -300,6 +301,10 @@ function parseWith(cfg={}) {
300301
const [i,r] = defn(0);
301302
if ( i===code.length ) {
302303
const [name,term] = r;
304+
if ( name == "Y" )
305+
console.warn("<span style=\"color:orange\">redefining Y is NOT RECOMMENDED and you do so at your peril</span>");
306+
if ( config.verbosity >= "Loquacious" )
307+
console.debug(`compiled ${ name }${ config.verbosity >= "Verbose" ? ` = ${ term }` : "" }`);
303308
return env.setThunk( name, wrap(name,term));
304309
} else
305310
error(i,"defn: incomplete parse");

tests/basics-binary-scott/solution.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ S = \ f g x . f x (g x)
1212
T = \ x f . f x
1313
V = \ x y f . f x y
1414
W = \ f x . f x x
15-
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
1615
Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )
1716

1817
#import Boolean.lc

tests/basics-binary-scott/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {assert} = chai;
44
const LC = require("../../src/lambda-calculus.js");
55
LC.config.purity = "LetRec";
66
LC.config.numEncoding = "BinaryScott";
7-
LC.config.verbosity = "Concise";
87

98
const solution = LC.compile();
109
const fromInt = LC.fromIntWith(LC.config);

tests/basics-church/solution.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ S = \ f g x . f x (g x)
1212
T = \ x f . f x
1313
V = \ x y f . f x y
1414
W = \ f x . f x x
15-
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
1615
Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )
1716

1817
#import ChurchBoolean.lc

tests/basics-church/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {assert} = chai;
44
const LC = require("../../src/lambda-calculus.js");
55
LC.config.purity = "LetRec";
66
LC.config.numEncoding = "Church";
7-
LC.config.verbosity = "Concise";
87

98
const solution = LC.compile();
109
const fromInt = LC.fromIntWith(LC.config);

tests/is-prime-scott/solution.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
B = \ f g x . f (g x)
44
I = \ x . x
55
K = \ x _ . x
6-
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
76
True = \ t f . t
87
False = \ t f . f
98
Succ = \ n z s . s n

tests/is-prime/solution.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# JohanWiltink
22

3-
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
43
True = \ t f . t
54
False = \ t f . f
65
Succ = \ n s z . s (n s z)

tests/multiply/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {assert} = require("chai");
33
const LC = require("../../src/lambda-calculus.js");
44
LC.config.purity = "LetRec";
55
LC.config.numEncoding = "Church";
6-
LC.config.verbosity = "Concise";
6+
// LC.config.verbosity = "Concise"; // reinstate for production
77

88
const {multiply} = LC.compile();
99

tests/prime-sieve/solution.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ S = \ f g x . f x (g x)
1515
T = \ x f . f x
1616
V = \ x y f . f x y
1717
W = \ f x . f x x
18-
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
1918
Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )
2019

2120
#import Ordering.lc

tests/prime-sieve/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {assert} = chai;
55
const LC = require("../../src/lambda-calculus.js");
66
LC.config.purity = "LetRec";
77
LC.config.numEncoding = "BinaryScott";
8-
LC.config.verbosity = "Concise";
98

109
const {primes} = LC.compile();
1110
const toInt = LC.toIntWith(LC.config);

0 commit comments

Comments
 (0)