develooper Front page | perl.perl5.porters | Postings from March 2016

[perl #127793] The cmp operator for user-defined classes lacksconsistency

Thread Previous | Thread Next
From:
Itsuki Toyota
Date:
March 28, 2016 13:11
Subject:
[perl #127793] The cmp operator for user-defined classes lacksconsistency
Message ID:
rt-4.0.18-28303-1459087553-1966.127793-75-0@perl.org
# 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.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About