Very odd Closure bug?
Stephan Rudlof
sr at evolgo.de
Thu Apr 6 14:21:15 UTC 2000
Henrik,
there was a discussion about
Full Closures - when do they close?
about two months ago; search for this words in the subject in your mails
or a mail archive.
But let's make some comments:
Henrik Gedenryd wrote:
>
> I got a very weird bug:
>
> after having done
>
> wrappedArguments _ (arguments collect: [:argNode | [argNode]]) asArray.
>
> --this evaluates to the last argNode for both elements of the resulting
> array.
>
> I suspect that this is "as should be" given the present state of the closure
> implementation,
Correct. We don't have BlockClosures in Squeak.
In squeak :argNode is semantically a variable at the same level as e.g.
dummy for e.g. these lines:
| dummy |
wrappedArguments _ (arguments collect: [:argNode | [argNode]]) asArray.
(you cannot write :argNode into the variable declaration, because of a
syntax error).
The blocks in wrappedArguments all have a binding to this one variable.
So all blocks in wrappedArguments share the variable :argNode, which has
the value of the last argument after generating wrappedArguments.
BTW:
wrappedArguments _ (arguments collect: [:argNode | [argNode] fixTemps])
asArray.
would probably work like you want to, but isn't semantically the same as
real BlockClosures.
Stephan
> but it might be something else--my mind goes into an
> infinite loop if I try to figure it out myself.
>
> Perhaps someone else is better fit to tell whether this is another,
> "genuine" bug.
>
> Changing the line to
>
> wrappedArguments _ (arguments collect: [:argNode | nil->argNode])
> asArray.
>
> fixes the problem, by the way (this exploits the coincidence that blocks as
> well as associations respond to #value).
>
> As the two elements happened to be the arguments to an ifTrue:ifFalse: , I
> thought at one point that there were some really strange boolean semantics
> going on.
>
> Henrik
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|