SortedCollection reversed...

Mark van Gulik ghoul6 at home.com
Thu Oct 11 10:57:27 UTC 2001


Creating a class BlockNegation that simply wraps an arbitrary block.  
Give it the same basic protocol as a two-argument block.  Heck, let it 
work for zero, one, or many arguments so you can easily use the same 
class for inverting the sense of a "select"-like filter.  If you wish, 
its instance creation can normally be triggered by sending a block the 
#not message.  If you send a BlockNegation a #not message you get back 
the block it wraps.  Make sure #numArgs (or whatever it's called in 
Squeak lately) is also implemented in BlockNegation (delegate to the 
wrapped block).

BTW, your description of Dolphin's species change an the resulting 
output didn't quite correspond (it looks like you claim #reversed 
produced a SortedCollection instead of an OrderedCollection).

-Mark


On Thursday, October 11, 2001, at 04:41 am, goran.hultgren at bluefish.se 
wrote:

> Hmmm, doing some archeology here:
>
> 'abd' asSortedCollection reversed -->  a SortedCollection($d $b $a)
>
> ...as expected but:
>
> 'abd' asSortedCollection reversed reSort --> a SortedCollection($a $b
> $d)
>
> ...ok, so reversed (obvious, if you check the implementation of
> reversed) is just a temporary state for SortedCollections. Hmm, is that
> logical/intentional/intuitive/good? (I checked in Dolphin and they have
> changed "self species" to "OrderedCollection" so that you actually do 
> not
> get a SortedCollection back. They noted the trickiness in maintaining an
> inverted sortBlock.)
>
> 'abd' asSortedCollection reversed add: $c; yourself --> a
> SortedCollection($d $b $a $c)
>
> ...not sorted anymore in either direction! Actually, it tried to put $c
> in the right place but fails since it is reversed.
>
> Questions:
>
> - First, why is there both #reverse and #reversed ? Both are called in
> numerous places and one is just implemented by calling the other. If
> #reverse was done "inplace" I could understand the difference in name
> (as reverse sounds like an imperative), but it isn't.
>
> - Ok, if we reimplement reverse/reversed for SortedCollections so that
> it remembers that it is reversed, how should it be done?
>
> - Sidequestion: If a class without subclasses implements #species as for
> example CharacterSet does (returning the class CharacterSet), what is
> the point in that? I mean, what is the difference from just inheriting
> Object>>species? Well, if it isn't in anticipation of new subclasses of
> course... :-)
>
> Thoughts:
>
> I experimented with wrapping the sortBlock in a reversing block - [:a :b
> | block value: b value: a ] - but I couldn't really figure out how to
> get it working without adding some state to SortedCollection in order
> for the SortedCollection to know when it has been reversed so that it
> could "unwrap" the sortblock again. A simpler approach is to just add
> another sortmethod and a boolean flag telling when being reversed, but
> that would mean another instvar.
>
> Anyway, just some ramblings... Set me straight! :-)
>
> regards, Göran
>
>




More information about the Squeak-dev mailing list