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

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

Thread Previous | Thread Next
From:
Damian Conway
Date:
August 22, 2012 16:56
Subject:
Re: Re: fixing smartmatch just hard enough (and when, too)
Message ID:
CAATtAp7AD3Enn+U3FRKSGAy_oW0kt3QPvy3=YBuX40jJHhf0qg@mail.gmail.com
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.
______________________________________________________________________


Damian

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