>> infix:<cmp> does numeric comparison if both operands are numbers, and 
>> string comparison otherwise.

That is a bit of an oversimplification.

> "Cmp" (like "eqv") depends on the particular type, so to sort a certain 
> way, you should need only to coerce the values to the right type:
>       @stuff.sort { .Num }         # numerically
>       @stuff.sort { ~ .name.uc }   # stringwise
>       @stuff.sort { Foo(%x{$_}) }  # foo-wise
> I don't know what cmp returns for two values of different types.   
> (Failure?)

Any type may define infix:<cmp> however it likes for two arguments of
its own type.  It may also define multis with other types that define
desirable coercions.  The infix:<cmp>:(Any,Any) routine is what would
be providing the default string coercion, so it would succeed for
any two different types that match Any and have string coercions.
Outside of Any are the Object and Junction types; I suppose cmp can
thread on junctions, but trying to sort junctions might well result
in aberrant behavior, especially if we choose a sort algorithm that
coredumps on circular ordering relations.  :)


Reply via email to