develooper Front page | perl.perl5.porters | Postings from August 2012

Re: Re: fixing smartmatch just hard enough (and when, too)

Thread Previous | Thread Next
Damian Conway
August 22, 2012 16:56
Re: Re: fixing smartmatch just hard enough (and when, too)
Message ID:
Hmmmm. In light of my arguments in defending bidrirctional overloading,
and of chromatic's observation regarding the relative ease of various types
of inversion-of-control on error reporting, I'm now convinced the
proposal should be:


Smartmatch (~~) table

    $a       $b                    Meaning
    =====    ===================   ========================
    Any      ~~-overloaded   [1]   $b->ol_method($a, 'rev')
    ~~-ol    Any             [1]   $a->ol_method($b)
    Any      undef                 ! defined $a
    Any      CodeRef, &{}-ol       $b->($a)
    Any      Regexp, qr-ol         $a =~ $b
    Any      unambiguous Num [2]   $a == $b
    Any      unambiguous Str [3]   $a eq $b
    Any      Any                   undef (with fatalizable warning)

    [1] Includes junctions, whose overloading distributes the
        smartmatch over their elements in their several ways.

    [2] If $b has an internal numeric representation but no
        internal string representation (or if some putative
        internal flag assures us it was originally a number).

    [3] If $b has an internal string representation but no
        internal numeric representation (or if some theoretical
        inner flag promises us it was initially a string).

The when construct

    Form                  Meaning
    ==================    ==================================
    when (EXPR)  {...}    if ($_ ~~ (EXPR))     {...; break}
    when {BLOCK} {...}    if ($_ ~~ sub{BLOCK}) {...; break}

    No exceptions.
    No special cases.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About