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

Re: smartmatch needs your eyes

Thread Previous | Thread Next
From:
Zefram
Date:
September 21, 2015 11:46
Subject:
Re: smartmatch needs your eyes
Message ID:
20150921114643.GN9229@fysh.org
Father Chrysostomos wrote:
>One big complaint was that, if you can write when(42), then
>$x=42;when($x) should do the same thing.

Yes.  Having different rules for literals would be a pain, in many
respects.

>        man when(42) to string comparison.  It will still cover 90% of
>the cases where people use it.

Are you expecting it to behave equivalently to == for numbers originating
from numeric processes (i.e., getting standard stringification)?
It doesn't:

$ perl -MData::Float=nextup -lwe 'print nextup(42) == 42 ? "yes" : "no"; print nextup(42) eq 42 ? "yes" : "no"'
no
yes

Behaviour also differs between == and eq on NaN.

Having ~~ mean eq when the rhs is a plain defined scalar is certainly
defensible, but don't expect it to be terribly useful on numbers.
Just to be clear, trying to split ~~ into stringy and numeric cases would
be worse.  There's no sane version of this that gets us decent implicit
numeric behaviour.

-zefram

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