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 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:
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.
After thinking about this some more, I remembered that one reason for a primitive to compare strings and not need to compare them twice is to save time. Given this, a simple primitive that just does a case insensitive compare and executes a block would be valuable.
I would guess, that the compare is the most expensive operation here (for longer strings) - the rest should be done in Smalltalk - simply because the format and specification of the specific blocks may vary according to the users needs .... as our both examples show.