source-academy/js-slang

Scoping issues in REPL when using explicit control variants

s-kybound opened this issue · 3 comments

The following program, entered statement by statement in separate cells into the REPL when using js-slang --variant=explicit-control, returns error "Name a not declared."

const a = 1;

const b = 1;

const c = a;

Any reference to a after const b = 1 returns an error.

The same behaviour can be seen with replacing const b = 1; with an IIFE such as (x => x)(a); - after the IIFE, a is not found.

I suspect this has to do with the way the current environment is handled (as an array of environments in context.runtime.environments).

Note: this problem does not seem to occur in Source Academy:
Screenshot 2024-03-30 at 6 16 41 PM

resolved with #1584

The problem persists, as functions defined using preludes are "forgotten" with each new program execution.

The following program, entered statement by statement in separate cells into the REPL when using js-slang --variant=explicit-control, returns error "Name map not declared."

map(x => x, list(1, 2, 3));

map;