Hi Group,
A little while I was thinking about how data got compared back when I worked on IBM mainframes (don't ask why my brain works in such a way that I should think about that). Anyway, those computers and I guess most computers today, do the comparison and set a flag (I think two bits) that indicates if the first item was less than, equal to or greater than the second. Branches can then be executed based upon the flag. In VA Smalltalk we would have to do the compare twice to get the same three conditions. For number, this is probably not too big a deal but for long strings it could matter.
I was thinking that it might be nice if Smalltalk virtual machines could mimic this kind of comparison in a way that didn't require doing the compare twice. I don't really have a need for this but someone might so I thought I would throw the idea out there. I took a look at VA Smalltalk and didn't find anything. I then took a look at Squeak and found a few methods that ultimately call a primitive to do the compare. The returned result is an integer 1, 2 or 3 indicating the less than, equal to or greater than condition.
The Squeak methods are:
compare: aString
compare: aString caseSensitive: aBool
compare: string1 with: string2 collated: order
where the first two, call the last one (with parameters set) and the last one calls the primitive. The primitive seems very general in that it has a collating order of characters parameter. I don't know if there would be much need for a collating order of characters parameter in VA Smalltalk. A case sensitive or insensitive option might be nice.
I do think that executing a block might be a better way to go than returning a number. Something like:
compare: aString ifLow: lowBlock ifEqual: equalBlock ifHigh: highBlock
This is more concise than having to do the compare and then test the number result to execute some code. One could alway put 1, 2 and 3 in the respective blocks to get the same results as Squeak if that was needed.
No one should feel any pressure to implement this on my account but maybe someone out there could use it to clean/speed up their code.
Lou