js-slang icon indicating copy to clipboard operation
js-slang copied to clipboard

Scoping issues in REPL when using explicit control variants

Open s-kybound opened this issue 1 year ago • 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).

s-kybound avatar Feb 19 '24 19:02 s-kybound

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

martin-henz avatar Mar 30 '24 10:03 martin-henz

resolved with #1584

s-kybound avatar Apr 12 '24 10:04 s-kybound

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;

s-kybound avatar Apr 14 '24 20:04 s-kybound