FAQ

On Sun Mar 27 07:11:14 2016, cookbook_000@yahoo.co.jp wrote:
Sorry, it is the post for perl6.
I mistook the category of this post.
But I don't have a permission to change that.
Looks like I do, I've moved it.

Tony

Search Discussions

  • Elizabeth Mattijsen via RT at Mar 28, 2016 at 3:03 pm

    On 27 Mar 2016, at 16:05, Itsuki Toyota (via RT) 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).

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl6-compiler @
categoriesperl
postedMar 27, '16 at 11:42p
activeMar 28, '16 at 3:03p
posts2
users1
websiteperl6.org

1 user in discussion

Elizabeth Mattijsen via RT: 2 posts

People

Translate

site design / logo © 2019 Grokbase