[FIX] SortedCollectionFix-sr

Stephan Rudlof squeak-dev at lists.squeakfoundation.org
Wed Oct 2 04:38:06 UTC 2002


Richard A. O'Keefe wrote:
> I noted that SortedCollection>>reversed produces an invalid answer.
> 
> Stephan Rudlof <sr at evolgo.de> replied:
> 	There may be a problem:  if you apply >>reversed multiple times
> 	the opposite comparison sortBlock becomes bigger and bigger, if
> 	the implementation just inverts it by constructing a new one
> 	with sending #not to the old.
> 
> As you say, IF.

> (Although #not is DEFINITELY the wrong thing to do.
> We want to turn <= into >+, not into > .)

Agreed (if you mean >= instead of >+ here).

> 
> 	There are other implementations possible, though.
> 	
> And indeed there are.
> 
> One of them is to introduce a new class
> 
>     Object subclass: #BinaryBlockConverse
>         instanceVariables: 'block'
>         ....
> 
>     beConverseOf: aBlock
> 	block := aBlock
> 
>     converse
> 	^aBlock
> 	
>     value: x value: y
> 	^block value: y value: x
> 
>     class>>
>     of: aBlock
> 	^self new beConverseOf: aBlock
> 
> and a new method in BlockContext
> 
>     converse
> 	self assert: [self numArgs = 2].
> 	^BinaryBlockConverse of: self
> 

This approach is elegant and minimizes recursion overhead.


Greetings,

Stephan

> I've just sent a change set "converse-raok" that basically does this.
> (No, it doesn't change SortedCollection reversed.)
> 
> 
> 


-- 
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