I noted that SortedCollection>>reversed produces an invalid answer.
Stephan Rudlof sr@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 > .)
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
I've just sent a change set "converse-raok" that basically does this. (No, it doesn't change SortedCollection reversed.)
Richard A. O'Keefe wrote:
I noted that SortedCollection>>reversed produces an invalid answer.
Stephan Rudlof sr@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.)
squeak-dev@lists.squeakfoundation.org