[squeak-dev] Problem with a Collection of Blocks

Julian Fitzell jfitzell at gmail.com
Thu Mar 5 22:20:38 UTC 2009


On Thu, Mar 5, 2009 at 10:36 PM, Joel Turnbull <joel at ardishealth.com> wrote:
>
> I'm trying to apply a collection of blocks to another collection to filter
> it. like...
>
> blockCollection := OrderedCollection new.
>   collectionWith1and2 do: [ :tag | blockCollection add: [ :collection |
> collection includes: tag ]].
> self halt.
>
> newCollection := collectionCollection copy.
> blockCollection do: [ :block | newCollection := newCollection select: block
> ].
>
> It's not really behaving though. the problem is that blockCollection doesn't
> get two different blocks referring two two different tags, but two identical
> blocks pointing to second tag. I included a test method below. I inserted a

You should actually be getting two different blocks but they will all
be accessing the local variable in the same method context. This is a
problem caused by Squeak not having full block closures (though you
may have noticed discussion about some progress on this on the list in
the past few days).

Seaside fixes this by adding a method #fixCallbackTemps to
BlockContext which looks like:

fixCallbackTemps
	| temps |
	home := home copy.
	home swapSender: nil.
	home isMethodContext
		ifFalse: [ ^ self ].
	temps := self tempVarRefs.
	1 to: home size do: [ :index |
		(temps includes: index)
			ifFalse: [ home tempAt: index put: nil ] ]

and calling it at appropriate places to avoid this problem. I'm not
certain what the suggested fix for non-Seaside users is at the moment.

Julian



More information about the Squeak-dev mailing list