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.
Here is @thelmuth’s brief description of environments, as currently implemented, copied from a github issue thread:
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
:exec
stack and executes it in a new environment. The environment_begin instruction does the same thing, but uses the entire rest of the:exec
stack. Environments can be ended in two ways: running out of code on the:exec
stack, and reaching anenvironment_end
instruction.
When an environment starts, it pushes the current Push state onto the
:environment
stack. 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 usereturn_X
andreturn_Y_pop
instructions. Thereturn_X
instructions have the name of a stack instead of X. When such an instruction is executed, that type is put onto the:return
stack, and when the environment finishes it will put the top item on the X stack onto the X stack in the base environment. Thereturn_Y_pop
instructions are similar, except they specify a stack to pop after returning from the environment, allowing a program to “consume” arguments.