Grokbase
x

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

View PostFlat  Thread  Threaded | < Prev - Next >
Paul Fenwick Re: Should (undef ~~ 0) be true? (was Re: pjf: dual life modules)
| +1 vote
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
G'day Rafael,

Rafael Garcia-Suarez wrote:

>>        undef ~~ 0                      # True
>> undef ~~ [0] # False!
>
> That's an inconsistency, and therefore a bug.

Oh good.

> I think that for backward compatibility sake, and possibly for undef
> commutativity sake, we should make undef ~~ 0 / "" not match. I'll do it
> as soon as possible.

Thank-you very much!  I've just rebuild blead, and it looks like now I don't
need to change any of the pod_examples.t tests at all.  New autodie patches
coming soon.

>> [undef] ~~ undef # True (currently false!)

> There, I don't get you. How can an array (a non-empty array) match undef ?
> The other cases I agree with.

Sorry, this is my 5.10.0 brain not fully grokking the new smart-match.  I
look at `[undef] ~~ undef` and think, "Aha!  We must go searching for undef
inside that array."

Of course, ~~ is no longer commutative, but I keep having a really hard time
forgetting that.  Moritz said I should try a strong drink, or a gold brick
wrapped around a lemon, but unfortunately I'm all out of Arcturan Mega-gin.

> Don't be sorry. You're one of the about 2 people who gave real-life,
> valuable and argumented feedback before 5.10.1 is out.

This actually has me worried.  I've been picking at smart-match when it's
intersected with me doing something with autodie, and I've done this purely
out of laziness; I don't want to have to change how autodie works.  I
haven't poked around with the rest of smart-match, although I promised I would.

So, to help fix that, I've written (as I think I promised to long ago), a
test case to find any surprises.  It's based upon the smart-match Perl tip
at http://perltraining.com.au/tips/2008-04-18.html . I'll send it as a
patch in a separate e-mail.  Currently, it gives me two surprises:

my @foo = qw(x y z xyzzy ninja);
 ok( @foo ~~ 'ninja' );  # Fails

my $array_ref = [5, 10, 15];
ok ( $array_ref ~~ 10 ); # Fails

Looking down the table in blead/perlsyn.pod, I see the first one has a
string on the RHS, and the RHS determines what we do.  It looks like that
falls through to the very last rule (Any/Any), which means we're doing
string equality.  That doesn't seem very useful; because unless we've
specially crafted our string, it's never going to be true.

The same seems to apply for the second one.  I assume we're triggering
Any/Num, which is doing a straight numerical equality.  Again, that doesn't
seem very useful.

If that's what really what these are triggering, then can I respectfully
suggest they're changed to search the list instead (as they would do if they
were reversed)?

All the best,

Paul

--
Paul Fenwick <pjf@perltraining.com.au> | http://perltraining.com.au/
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia | Fax: +61 3 9354 2681

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 >