Support for “environments” is implemented in Clojush, but the utility of environments has not yet been extensively tested. It is possible that the feature will be refined after such testing takes place.
The idea behind environments is to execute some code in a local scope, so that the code doesn’t affect the other stacks.
There are two ways to start an environment. environment_new takes the top block of code on the
:execstack and executes it in a new environment. The environment_begin instruction does the same thing, but uses the entire rest of the
:execstack. Environments can be ended in two ways: running out of code on the
:execstack, and reaching an
When an environment starts, it pushes the current Push state onto the
:environmentstack. When it finishes, it pops the top of the environment stack, restoring the state as it was before the environment started. The only way for code inside an environment to affect the rest of the program is to use
return_Xinstructions have the name of a stack instead of X. When such an instruction is executed, that type is put onto the
:returnstack, and when the environment finishes it will put the top item on the X stack onto the X stack in the base environment. The
return_Y_popinstructions are similar, except they specify a stack to pop after returning from the environment, allowing a program to “consume” arguments.