bindingOf question?

Colin Putney cputney at wiresong.ca
Sat Nov 20 16:41:14 UTC 2004


First Stéphane Ducasse wrote:

>> Hi all
>>
>> I'm wondering why the definition of bindingOf: is the following one:
>>
>> Behavior>>bindingOf: varName
>> "Answer the binding of some variable resolved in the scope of the
>> receiver"
>> ^superclass bindingOf: varName
>>
>> and not something more like that.
>>
>>        binding := self environment bindingOf: aSymbol.
>> binding ifNotNil:[^binding].
>>
>> "Finally look higher up the superclass chain and fail at the end."
>> superclass == nil
>> ifTrue: [^ nil]
>> ifFalse: [^ superclass bindingOf: aSymbol].
>>
>> It seems to me that the current Behavior>>bindingOf is bogus.

Well, this would make Behavior>>bindingOf: more consistent with the 
implementations in Class and Metaclass. On the other hand, I've never 
heard a good explanation of why the environment is searched before 
delegating to the superclass. The way Smalltalk is organized, you would 
think (or at least I would) that globals would be the outermost lexical 
scope, but that's not the case. Another sign that this is fishy is that 
when you are searching for a variable that is defined several levels up 
your superclass chain - or not at all - the environment gets searched 
repeatedly.

My best guess as to why this is the case is that the superclass chain 
might contain classes in other environments - ones that aren't part of 
this environment's parent chain - and we want this environment to trump 
the superclass environment. That also sounds a bit fishy - how the heck 
do you sublcass something that isn't in your environment - but ok, 
maybe there's a good reason for it.

Still it seems to me that if we aren't going to actually use multiple 
environments we ought to make the scoping hierarchy more sensible. BTW, 
just in case the fact that we only have one environment today is a 
tools issue, I've tried to make OmniBrowser as environment-agnotistic 
as possible. It takes an environment as the root of its node graph and 
asks classes for their environment rather than referring to Smalltalk. 
IIRC, the one or two places where this breaks down is when dealing with 
system navigation (senders, implementers etc.) It would be nice to be 
able to do something like [aClass environment navigator] rather than 
having a single global navigator that is hardcoded to Smalltalk.

Then Andrew Tween wrote:

> I don't believe that the Behavior>>bindingOf: method is ever executed.
> bindingOf: is reimplemented in both Class and MetaClass, and neither of
> those does a 'super bindingOf: '.
> I put a 'self halt' into Behavior>>bindingOf: , and didn't get a 
> Debugger.
>
> Having said that, there are 2 subclasses of Behavior which 'might' 
> need the
> Behavior>>bindingOf: method, namely, Oop and Unsigned.
> These classes appear to be part of VMMaker, but I don't know whether 
> you
> would ever, meaningfully, send bindingOf: to instances of those 
> classes.
>
> So, I suspect that Behavior>>bindingOf: can be safely deleted, or 
> changed to
> bindingOf: varName self subclassResponsibiliy'

Yes, but what if you aren't using a subclass of Behavior? One might 
want to create instances of Behavior its self. In that case you'd want 
the behavior to have a working #bindingOf: so that you can compile 
methods for it.

Colin




More information about the Squeak-dev mailing list