develooper Front page | perl.perl5.porters | Postings from October 2015

Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]

Thread Previous | Thread Next
From:
D Perrett via perl5-porters
Date:
October 19, 2015 20:01
Subject:
Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]
Message ID:
CABrou+nZMk5vgJZZdnLixCSd1497zTf1TPjErTURWVJ3dN+=0w@mail.gmail.com
If I've undertstood correctly,

    $x ~~ $y

is intended to mean one of (inter alia)

    $x == $y
    $x eq $y

... depending on the type of $y. The problem is working out which of
those two operators should work.

The utility of smartmatch/given/when is that it is supposed to value
DWIM over nitpicking. It is the "I don't want to have to think about
it" operator, which values recall over precision. That is, it should
err on the side of true over false.

Therefore, aren't real users going to be least surprised by something
that does...

    $x == $y || $x eq $y

?

This would mean $number_three ~~ "3\n" is true when I forget to chomp
just like $number_three == "3\n". The only case I can see where that's
really wrong is "inferior" ~~ "informative" and 0 ~~ ''; and I wonder
if ~~ could special-case inf strings and empty strings.

Disclaimer: I don't use smartmatch, and this isn't going to entice me to use it.

Daniel

On 19 October 2015 at 13:52, demerphq <demerphq@gmail.com> wrote:
> On 19 October 2015 at 05:11, Zefram <zefram@fysh.org> wrote:
>> Ricardo Signes wrote:
>>>On the other hand, a future &num could provide a faster magic value that ~~'s
>>>implementation can know to directly resolve to a numeric comparison.  I'd doubt
>>>it would ever match custom when:num syntax in speed,
>>
>> It totally could, without any real difficulty.
>
> No offence intended Zefram, but what *you* consider "easy" or
> "obvious" most people don't. Even on this list. :-)
>
> Yves
>
>
> --
> perl -Mre=debug -e "/just|another|perl|hacker/"

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