source-academy/js-slang

CSE Machine: Keep id of environments, arrays & closures constant across different steps

Closed this issue · 0 comments

The Environment and Closure objects currently have an id property that is not very useful. As the user run the CSE Machine and goes to the next steps, the id will always change between frames, since js-slang using the uniqueId() function from lodash to set the id.

It would be nice if id stays the same for the same environments, arrays and closures across different steps of a program. This would mean that arrays should also have an id property. Having the id stay the same could pave the way for better performance on the frontend (through re-use and mutation of objects that have the same id), and allow for more complex CSE machine animations inside the environment regarding movement of multiple different objects.

An idea would be to have a class variable that resets to 0 when the program first starts. When any environment, array and closure is first created, we assign that variable to the id, and increment it. Since the program execution from the beginning is consistent across different steps, the id values should also remain consistent for the same environments, arrays and closures.