Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: undef == 0?

by stu42j (Sexton)
on Oct 25, 2007 at 05:09 UTC ( [id://647076]=note: print w/replies, xml ) Need Help??


in reply to Re: undef == 0?
in thread undef == 0?

1 and 2 are both true in boolean context so does that mean that 1 == 2?

Replies are listed 'Best First'.
Re^3: undef == 0?
by codeacrobat (Chaplain) on Oct 25, 2007 at 06:21 UTC
    == forces scalar context. Both 1 and 2 are treated as decimal integers. Obviously they are not the same.

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
      Uhm, yeah. That was a rhetorical question type thing in response to swampyankee's suggestion that since undef and 0 are both false then it logically follows that undef == 0 should also be true. I was just giving an example where boolean equality is not equivalent to numeric equality.
Re^3: undef == 0?
by mrpeabody (Friar) on Oct 25, 2007 at 16:12 UTC
    No, what it means is that is_true(1) == is_true(2), where is_true is something like sub { $_[0] ? 1 : 0 }
Re^3: undef == 0?
by swampyankee (Parson) on Oct 26, 2007 at 00:08 UTC

    It does mean that 1 && 2 evaluates to true. And, were Perl to have Fortran-style logical comparison operators (.EQV. and .NEQV.; this gives me an idea for an Acme module...), 1 eqv 2 would evaluate to true.

    Every language has its little corners which may not be that well thought out; undef& == 0 evaluating to true may be one of them (00 evaluating to 1 is probably another). It is consistent, and arguably reasonable, behavior, although it's just as sensible, and arguably more reasonable, to have undef behave like NaN and not be comparable to anything, even itself (NaN == NaN and NaN != NaN are both false in most languages).


    emc

    Information about American English usage here and here.

    Any Northeastern US area jobs? I'm currently unemployed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://647076]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found