@@ -345,16 +345,16 @@ export function compile(code) {
345
345
function evalLC ( term ) {
346
346
347
347
// builds function to return to user ( representing an abstraction awaiting input )
348
- function awaitArg ( term , stack , env ) {
348
+ function awaitArg ( term , env ) {
349
349
// callback function which will evaluate term.body in an env with the input
350
350
function result ( arg ) {
351
351
let argEnv ;
352
352
if ( arg ?. term && arg ?. env ) ( { term : arg , env : argEnv } = arg ) ; // if callback is passed another callback, or a term
353
353
const termVal = new Tuple ( typeof arg === 'number' ? fromInt ( arg ) : arg , new Env ( argEnv ) ) ;
354
354
if ( term . name === "_" )
355
- return runEval ( new Tuple ( term . body , new Env ( env ) ) , stack ) ;
355
+ return runEval ( new Tuple ( term . body , new Env ( env ) ) ) ;
356
356
else
357
- return runEval ( new Tuple ( term . body , new Env ( env ) . setThunk ( term . name , termVal ) ) , stack ) ;
357
+ return runEval ( new Tuple ( term . body , new Env ( env ) . setThunk ( term . name , termVal ) ) ) ;
358
358
}
359
359
return Object . assign ( result , { term, env} ) ;
360
360
}
@@ -363,8 +363,8 @@ function evalLC(term) {
363
363
// isRight :: bool (indicating whether the term is left or right side of an Application)
364
364
// isEvaluated :: bool (indicating whether the current term should be stored in the Env)
365
365
// callstack :: [String] (History of var lookups, for better error messages)
366
- function runEval ( { term, env} , stack ) { // stack: [[term, isRight, isEvaluated]], term: LC term, env = Env { name => term }
367
- const callstack = [ ] ; // Does not persist between requests for arguments
366
+ function runEval ( { term, env} ) { // stack: [[term, isRight, isEvaluated]], term: LC term, env = Env { name => term }
367
+ const callstack = [ ] , stack = [ ] ; // Does not persist between requests for arguments
368
368
while ( ! ( term instanceof L ) || stack . length > 0 ) {
369
369
if ( term instanceof V )
370
370
if ( term . name === "()" )
@@ -377,7 +377,7 @@ function evalLC(term) {
377
377
else {
378
378
if ( res . term instanceof V || res . term instanceof A )
379
379
// Push a frame to the stack to indicate when the value should be stored back
380
- stack . push ( [ new Tuple ( term , env ) , false , true ] ) ;
380
+ stack . push ( [ new Tuple ( term , env ) , true , true ] ) ;
381
381
( { term, env} = res ) ;
382
382
}
383
383
}
@@ -395,7 +395,7 @@ function evalLC(term) {
395
395
env = new Env ( env ) . setThunk ( term . name , new Tuple ( lastTerm , lastEnv ) ) ;
396
396
term = term . body ;
397
397
} else { // Pass the function some other function.
398
- term = lastTerm ( awaitArg ( term , [ ] , env ) ) ;
398
+ term = lastTerm ( awaitArg ( term , env ) ) ;
399
399
}
400
400
} else if ( term instanceof Tuple ) {
401
401
// for primitives
@@ -421,9 +421,9 @@ function evalLC(term) {
421
421
}
422
422
}
423
423
// We need input
424
- return awaitArg ( term , stack , env ) ;
424
+ return awaitArg ( term , env ) ;
425
425
}
426
- return runEval ( term , [ ] ) ;
426
+ return runEval ( term ) ;
427
427
}
428
428
429
429
// Print an error, with stack trace according to verbosity level
0 commit comments