Skip to content

Commit c6a4d74

Browse files
author
Johan Wiltink
committed
unmake Y a primitive
it only saves compile time, not runtime removed the warning about it as well
1 parent 345f5b5 commit c6a4d74

File tree

7 files changed

+9
-4
lines changed

7 files changed

+9
-4
lines changed

src/lambda-calculus.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ function Primitive(v) { return new Tuple(new V( "<primitive>" ), new Env([[ "<pr
9696

9797
const primitives = new Env;
9898
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 ) );
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"))))));
100101

101102
function fromInt(n) { return fromIntWith()(n); }
102103

@@ -195,7 +196,7 @@ function parseWith(cfg={}) {
195196
if ( verbosity >= "Concise" ) console.error(`parse: while defining ${ name } = ${ term }`);
196197
throw new ReferenceError(`undefined free variable ${ nm }`);
197198
}
198-
} , new Tuple( FV.has(name) ? new A(env.getValue("Y"),new L(name,term)) : term , new Env ) );
199+
} , new Tuple( FV.has(name) ? new A(Y,new L(name,term)) : term , new Env ) );
199200
else if ( purity==="PureLC" )
200201
if ( FV.size ) {
201202
if ( verbosity >= "Concise" ) console.error(`parse: while defining ${ name } = ${ term }`);
@@ -301,8 +302,6 @@ function parseWith(cfg={}) {
301302
const [i,r] = defn(0);
302303
if ( i===code.length ) {
303304
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>");
306305
if ( config.verbosity >= "Loquacious" )
307306
console.debug(`compiled ${ name }${ config.verbosity >= "Verbose" ? ` = ${ term }` : "" }`);
308307
return env.setThunk( name, wrap(name,term));

tests/basics-binary-scott/solution.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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) )
1516
Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )
1617

1718
#import Boolean.lc

tests/basics-church/solution.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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) )
1516
Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )
1617

1718
#import ChurchBoolean.lc

tests/is-prime-scott/solution.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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) )
67
True = \ t f . t
78
False = \ t f . f
89
Succ = \ n z s . s n

tests/is-prime/solution.txt

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

3+
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
34
True = \ t f . t
45
False = \ t f . f
56
Succ = \ n s z . s (n s z)

tests/prime-sieve/solution.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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) )
1819
Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )
1920

2021
#import Ordering.lc

tests/scott-lists/solution.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ S = \ f g x . f x (g x)
1414
T = \ x fn . fn x
1515
V = \ x y fn . fn x y
1616
W = \ f x . f x x
17+
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
1718
#import scott-booleans.ls
1819
False = K
1920
True = KI

0 commit comments

Comments
 (0)