beginGlobalContext
Start a new global context in which the variables and their values are stored.
beginGlobalContext(contextName)
| Inputs |
contextName |
A string which is the name of the context. |
Description
Any variables definitions bracketted by this call
and a subsequent call to endContext will be stored
in a context with the specified name.
The variables defined in the context may be later
made accessible by making a call to beginGlobalContext
with the same
context name as the argument.
Note that the contexts defined within a function in this manner are
global,
and are available even when the function terminates. Note also
that the global statement may also be used to share variables
with the main global context. However, the use of beginGlobalContext
may have the benefit of encapsulating the globally shared
variables in a single named object.
Example
>>function f(x)
> beginGlobalContext("gc")
> a=x+2
> b=x+3
> endContext()
>end
>>f(10)
New context:gc
>>a
null
>>b
null
>>beginContext("gc")
New context:gc
>>a
12
>>b
13
>>endContext()
>>a
null
>>// The variables in the context may also be accessed as if
>>// it was a hashtable.
>>gc.a
12