Zen and the Art of Scope Maintenance: An Inquiry into Contexts
Context is essentialy a namespace
Two key points to get it:
- Every word is bound to global context by default at load time (source as text to Red values).
- Local contexts are constructed at run-time.
- Each context constructor will determine which words it should capture by either looking into a declared list (locals in functions), or gather all the set-words (objects).
- Then, the constructor will go through the nested blocks in the body to bind all the “local” words. When applied in nested way
object [... object [... func [...][...]]], the various binding passes will produce a result which mimic nested scopes.
- That is what we call
With dynamic scoping we have chains of function calls to traverse, with static scoping we have chains of definitions, but with definitional “scoping” there’s no chains at all, hence there’s no
spoon scopes! Multiple rounds of bindings give an illusion of nesting (i.e. static scoping), while in fact all contexts are completely separate, w/o any hierarchy between them.