On 14 Dec 2013, at 16:15, Norbert Hartl <[email protected]> wrote:
>
> Am 14.12.2013 um 15:58 schrieb kilon alios <[email protected]>:
>
>> yes sorry i meant global variables , the ones you define in workspace like a
>> := 1.
>>
> Those aren’t globals. Everything you do in the workspace is compiled as
> method (UndefinedObect>>#DoIt) and executed. There are only a handful of
> global values and there is the smalltalk dictionary where names can be looked
> up.
>
They live in the “bindings” ivar of Workspace.
When you compile code with the “requestor” not nil, it will put a
OCRequestorScope into the scope chain.
This means that when Opal Semantic analysis asks the scope for the definition
of a name, it will call
#lookupVar: on that scope, which is then doing:
(requestor bindingOf: name asSymbol) ifNotNil: [:assoc |
^ OCLiteralVariable new assoc: assoc; scope: self; yourself].
^ super lookupVar: name.
Which means that variables in the Workspace are compiled as literal variables
(like globals),
but the binding comes from a dictionary that is in the ivar “bindings” of the
Workspace.
Marcus