[Parrot-users] Numerical and string comparisons in Squaak (and PIR)

Patrick R. Michaud pmichaud at pobox.com
Thu Feb 3 16:27:58 UTC 2011


On Thu, Feb 03, 2011 at 10:18:21AM +0100, Fredrik Rothamel wrote:
> >In other words, the type of comparison performed always depends on
> >the type of the first IN operand, and you have to do explicit casting
> >if you want some other form of comparison.
> 
> Nice example. Describes the behaviour very clearly.
> 
> I was thinking of how to best implement casting in the second
> comparison above.
> Should I create a new string class overriding the cmp method?

You could do that, but I think that then makes the opposite
assumption that _all_ comparisons using strings will be numeric.

In Rakudo and the other languages I've worked with, we've tended to
avoid the casting issue by using the 'cmp_num' and 'cmp_str' opcodes 
and then using 'islt' on the result of that.  

Pm


More information about the Parrot-users mailing list