[squeak-dev] Problem with a Collection of Blocks

Joel Turnbull joel at ardishealth.com
Thu Mar 5 21:36:47 UTC 2009


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 halt where if you explore blockCollection you can 
drill down into home: and see that the date is 6 March 2009 on both 
blocks in the collection.

Both tests fail, and I don't understand why :) If there's an alternative 
strategy for applying multiple filters I'd love to hear it too.
Thanks, Joel

testUpdateCollectionFromBlocks
| newCollection |
   
    tag1 := Date year: 2009 month: 3 day: 5.
    tag2 := Date year: 2009 month: 3 day: 6.

    collectionWith1and2 := OrderedCollection new.
    collectionWith1and2 add: tag1; add: tag2.

    collectionWith2 := OrderedCollection new.
    collectionWith2 add: tag2.

    collectionCollection := OrderedCollection new.
    collectionCollection add: collectionWith1and2;    add: collectionWith2.
                       
    blockCollection := OrderedCollection new.
    collectionWith1and2 do: [ :tag | blockCollection add: [ :collection 
| collection includes: tag ]].
    self halt.

    newCollection := collectionCollection copy.
    blockCollection do: [ :block | newCollection := newCollection 
select: block ].
   
    self assert: ( newCollection = ( ( OrderedCollection new ) add: 
collectionWith1and2 ) ).
    self deny: ( newCollection = collectionCollection ).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5145 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090305/49877569/smime.bin


More information about the Squeak-dev mailing list