Skip to content

Commit 8d7d1c8

Browse files
authored
Merge pull request #75 from Kacarott/main
Fix #74
2 parents 577e5f6 + 704f2d0 commit 8d7d1c8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/lambda-calculus.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ export function fromInt(n) {
133133
export function toInt(term) {
134134
try {
135135
if ( config.numEncoding === "Church" ) {
136-
return term ( x => x+1 ) ( Primitive(0) );
136+
const succ = x => x+1 ;
137+
const result = term ( succ ) ;
138+
return result ( result === succ ? 0 : Primitive(0) );
137139
} else if ( config.numEncoding === "Scott" ) {
138140
let result = 0, evaluating = true;
139141
while ( evaluating )

tests/basics-church/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ describe("Church tests",function(){
3636
assert.equal( times(1e2)(1e1), 1e3 );
3737
assert.equal( pow(10)(3), 1e3 );
3838
assert.equal( pred(pow(10)(3)), 1e3-1 );
39+
assert.equal( pow(0)(0), 1);
3940
});
4041
});

0 commit comments

Comments
 (0)