Grokbase
x

Re: Should (undef ~~ 0) be true? (was Re: pjf: dual life modules)

View PostFlat  Thread  Threaded | < Prev - Next >
Abigail Re: Should (undef ~~ 0) be true? (was Re: pjf: dual life modules)
| +1 vote
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Tue, Jun 30, 2009 at 02:11:50AM +1000, Paul Fenwick wrote:
>
> These all seem to relate to how 5.10.1 smart-match handles undef. In
> particular:
>
>  undef ~~ 0;  # True! (undef is coerced to 0)
>  undef ~~ "";  # True! (undef is coerced to "")
>
> Consequently, this also means the following prints "I've got a zero".
>
>  my $x = undef;
>
>  given ($x) {
> when (0) { say "I've got a zero!" } # printed
>   default  { say "I've got something else" }
>  }
>
> This means that for 5.10.1, any given/when block is going to need a separate
> case for undef before any string/numeric tests if we want to avoid treating
> it like 0/"". I don't know about everyone else, but I *never* want to treat
> undef as if it's defined. If I did, I have now have the new // (defined-or)
> operator to make that easy. As such, it's a *big* surprise to have
> smart-match go coercing undef so readily.

I think no matter what choice will be made (undef is separate from 0/"";
undef is coerced to 0; undef is coerced to ""), you will encounter
situations where you wished the other choice was made. From experience,
sometimes I want 'undef' to be different from 0 and/or "". Often I want
'undef' and "" to be the same, but different from 0 (// isn't helping
there - a 'length' which doesn't warn on undef would help). Other times,
I want any false scalar value to be lumped together.

Therefore, I have no opinion on whether

    undef ~~ 0

and/or

    undef ~~ ""

should be true or false. Any choice will be surprising for some, and obvious
for others.

As long as there's some consistency.



Abigail

Thread : Re: pjf: dual life modules (autodie)
1)
Paul Fenwick G'day Dave, There's autodie 1.999_01 on the CPAN. It supports the hinting interface, has tests, and...
2)
Paul Fenwick G'day Dave, Autodie 2.00 has finally been released, and is making its way through the CPAN. It has...
3)
Tux Thanks, patch successfully applied as 9b657a623c3928518095c706c37ba6315469a48e
4)
Rafael Garcia-Suarez 2009/6/29 H.Merijn Brand <h.m.brand@xs4all.nl>: I have two failures in bleadperl:...
5)
Paul Fenwick I can also reproduce these under cygwin/blead. That'll teach me to post patches before I've...
6)
Paul Fenwick G'day Rafael / p5p, For autodie, hints.t is fixed in my git repository. Those tests were failing...
7)
Abigail I think no matter what choice will be made (undef is separate from 0/""; undef is coerced to 0;...
8)
Rafael Garcia-Suarez 2009/6/29 Paul Fenwick <pjf@perltraining.com.au>: That's an inconsistency, and therefore a bug. I...
9)
Rafael Garcia-Suarez 2009/7/1 I: commit fb51372e8e462d7f3320e8a1b91a913f976aae12 Author: Rafael Garcia-Suarez...
10)
Ricardo SIGNES Waaaaah? I am so confused. This is more special casing. $x~~$str means $x eq $str. undef eq ''. I...
11)
David E. Wheeler I was wondering the same thing. The previous behavior made sense to me because it was consistent...
12)
Paul Fenwick G'day Rafael, Oh good. Thank-you very much! I've just rebuild blead, and it looks like now I don't...
13)
Rafael Garcia-Suarez 2009/7/1 Paul Fenwick <pjf@perltraining.com.au>: tip at sn't hey No, because if we have given...
14)
Paul Fenwick G'day Rafael / p5p, I *think* I get it... If `$array_ref ~~ 10` is allowed to search @$array_ref...
15)
Ricardo SIGNES That footnote appears to have been lost during transmission. What do you suggest is in $x? A simple...
16)
Paul Fenwick It was going to be something about specially formatted strings/numbers that matched stringified...
17)
Paul Fenwick A whole lot of stuff with his vocab hashing to the wrong entries. Please consider:...
18)
Ricardo SIGNES It's funny, because I find the new behavior *much* more straightforward and easy to explain than...
19)
Paul Fenwick Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit G'day Rafael / p5p, As...
spacer
View PostFlat  Thread  Threaded | < Prev - Next >