[Grace-core] [Minigrace] inheritance and closures

Michael Homer mwh at ecs.vuw.ac.nz
Mon Jun 4 18:42:22 PDT 2012


On Tue, Jun 5, 2012 at 10:44 AM, Kim Bruce <kim at cs.pomona.edu> wrote:
> Hi,
>
> Here is a problem I've been puzzling over for quite a while, though I think I finally figured it out.  I believe it is a semantic error in the compiler, but I'm not positive.  Take a look at the program below and then at my explanation in the next few paragraphs.
> Is this the correct semantics?  I've been trying to figure that out, given that the closure is what is being passed, and that seems to be statically determined.  However, in the end, I believe it is wrong.  I believe that since this was all being executed as part of the constructor for Clicker, the self should have been the self for Clicker that was bound in the closure.  Thus I should have gotten the semantics I expected -- where the doSomething for Clicker was executed rather than the one for DrawingCanvas.
>
> I'm happy to have someone explain why I'm wrong, but for now I think its a compiler bug.  What do you think?
I think so, or at least it wasn't what I intended. It is an artifact
of performing inheritance by delegation, and the binding of a block's
self when it's created. But conceivably it could be the right thing to
do (it is lexical scope - the unqualified call without "self." is more
ambiguous).
-Michael


More information about the Grace-core mailing list