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 19:52
Subject:
Re: Re: fixing smartmatch just hard enough (and when, too)
Message ID:
CAATtAp7JjuX9qvgs1jDSzR=0297b0qJzX2mCQC3jgMqMZd-ztw@mail.gmail.com
Rick posited:

> Case one:     $x ~~ *main
>
> Case two:  $y = 1.23;  print $y;  $x ~~ $y;
>
> My gut is that both should warn,
> and only the first should fail.

Interesting. In contrast, I see those two cases as being
exactly the same.  Namely: "Failed because unable to smartmatch".

I would have thought the various kinds of failures would be more
consistent like this:

    $Zero   = 0;
    $Num    = 1;
    $Str    = "1";
    $NumStr = 1; print $numstr;

    $Zero ~~ *GLOB    # unmatchable (invalid type) -----> undef
    $Zero ~~ \%HASH   # unmatchable (invalid type) -----> undef
    $Zero ~~ \@ARRAY  # unmatchable (invalid type) -----> undef
    $Zero ~~ $NumStr  # unmatchable (ambiguous types) --> undef
    $Zero ~~ $Num     # matchable but == didn't match --> ""
    $Zero ~~ $Str     # matchable but eq didn't match --> ""

That is: defined-but-false when the smartmatch was attempted, but failed;
         undef-ergo-false when the smartmatch wasn't even attempted.

...and with a warning issued in any case where undef is returned.

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