> On 27 Mar 2016, at 16:05, Itsuki Toyota (via RT) <perlbug-follo...@perl.org> > wrote: > > # New Ticket Created by Itsuki Toyota > # Please include the string: [perl #127793] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=127793 > > > > It seems that the cmp operator for user-defined classes lacks consistency. > See the following commands. > > $ perl6 -e 'class MyClass {}; my $foo = MyClass.new(); my $bar = > MyClass.new(); ($foo cmp $bar).perl.say' > Order::Less > $ perl6 -e 'class MyClass {}; my $foo = MyClass.new(); my $bar = > MyClass.new(); ($bar cmp $foo).perl.say' > Order::More > $ perl6 -e '(Str.new cmp Str.new).perl.say' > Order::Same > > Comparing two instances of the type object Str seems to check its type, but > comparing that of MyClass seems to check its address or something. > > I think that it should return Order::Same or something Exception.
The default cmp calls .Stringy on the objects, so effectively the comparison becomes something like "MyClass<123345>" cmp "MyClass<234556>”. I guess we *could* introspect the object for public attributes and start cmp-ing them (if they are of the same type, of course). But I fear for the level of DWIM: it looks like becoming a WAT very fast. Perhaps we should only check for address equality, and if not, return Nil (indicating we don’t know).