Uri Guttman wrote:
>>>>>> "LW" == Larry Wall <la...@wall.org> writes:
>   >>> infix:<cmp> does numeric comparison if both operands are numbers, and 
>   >>> string comparison otherwise.
>   LW> That is a bit of an oversimplification.
>   LW> Any type may define infix:<cmp> however it likes for two arguments of
>   LW> its own type.  It may also define multis with other types that define
>   LW> desirable coercions.  The infix:<cmp>:(Any,Any) routine is what would
>   LW> be providing the default string coercion, so it would succeed for
>   LW> any two different types that match Any and have string coercions.
>   LW> Outside of Any are the Object and Junction types; I suppose cmp can
>   LW> thread on junctions, but trying to sort junctions might well result
>   LW> in aberrant behavior, especially if we choose a sort algorithm that
>   LW> coredumps on circular ordering relations.  :)
> this means cmp still does a string compare as long as it can coerce its
> args to strings.

... and as long as no other multis are specified.
I know at least of infix:<cmp>(Num $a, Num $b) (which does the same as
Perl 5's <=>) and infix:<cmp>(Pair $a, Pair $b) (which does $a.key cmp
$a.key || $a.value cmp $b.value), so numbers and pairs DWIM. Likewise
sorting of AoAs is specified to first sort on the first items, then on
the seconds etc.


Reply via email to