When is a closure a real one? [was: Real closures]

Michael Haupt mhaupt at gmail.com
Sun Oct 8 16:17:22 UTC 2006


Hi,

On 10/8/06, J J <azreal1977 at hotmail.com> wrote:
> I am not familiar enough with those calls to say 100%, but when I say "real
> closures", what I mean are closures that can be returned from a function and
> used without fear.  In other words, what other languages that have closures
> do.
>
> Now I relize the "return to home context" (i.e. ^) is not compatible with
> this, but that's ok.  This ability is unique to smalltalk as far as I know
> and treating it different would be fine (e.g. if a ^ is seen then turn the
> block into the cheaper BlockContext since it can't be returned from a method
> anyway).

I'm not sure whether I understand your correctly, but I think that the
problem in Squeak is something different (as Philippe already
mentioned). As for ^, it is *good* that it returns from the lexical
context of the block it occurs in.

Imagine what would happen in a setting like this:

SomeClass>>someMessage
    self someCondition ifTrue: [ ^10 ] ifFalse: [ ^20 ]

if ^ was defined to return from the dynamic scope. In that case, it
would return from #ifTrue:ifFalse: (or wherever the blocks would be
evaluated), instead of #someMessage, which is the intention. Crazy
behaviour. 8-)

Best,

Michael



More information about the Squeak-dev mailing list