Dynamic variables
Factor handbook ยป The language

Prev:Lexical variables
Next:Global variables


The namespaces vocabulary implements dynamically-scoped variables.

A dynamic variable is an entry in an assoc of bindings, where the assoc is implicit rather than passed on the stack. These assocs are termed namespaces. Nesting of scopes is implemented with a search order on namespaces, defined by a namestack. Since namespaces are just assocs, any object can be used as a variable. By convention, variables are keyed by Symbols.

The get and set words read and write variable values. The get word searches the chain of nested namespaces, while set always sets variable values in the current namespace only. Namespaces are dynamically scoped; when a quotation is called from a nested scope, any words called by the quotation also execute in that scope.
get ( variable -- value )

set ( value variable -- )


Various utility words provide common variable access patterns:
Changing variable values
Namespace combinators

Implementation details your code probably does not care about:
Namespace implementation details

Dynamic variables complement Lexical variables.