source-academy / js-slang

Implementations of sublanguages of JavaScript, TypeScript, Scheme and Python
https://source-academy.github.io/source/
Apache License 2.0
67 stars 104 forks source link

Scoping issues in REPL when using explicit control variants #1550

Open s-kybound opened 8 months ago

s-kybound commented 8 months ago

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).

martin-henz commented 6 months ago

Note: this problem does not seem to occur in Source Academy:

Screenshot 2024-03-30 at 6 16 41 PM
s-kybound commented 6 months ago

resolved with #1584

s-kybound commented 6 months ago

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;