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

Re: smartmatch needs your eyes

Thread Previous | Thread Next
September 21, 2015 11:46
Re: smartmatch needs your eyes
Message ID:
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

>        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"'

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.


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