Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: The mystery of double negation (bool 0)

by tye (Sage)
on Jul 12, 2015 at 22:51 UTC ( [id://1134431]=note: print w/replies, xml ) Need Help??


in reply to Re^2: The mystery of double negation
in thread The mystery of double bitwise negation

The point of Double Negation is casting [...] any false value to 0.
Nope, it's bitwise negation and doesn't work this way. It's basically - noop. Keeps value the same.

Um:

% say "(!1)" % say "~~(!1)" 0

So it could be an idiom that is applied to all Boolean values (so that Boolean false shows up as '0' instead of as the "invisible" ''). It just does nothing when the Boolean value is already 1.

- tye        

Replies are listed 'Best First'.
Re^4: The mystery of double negation (bool 0)
by zwon (Abbot) on Jul 13, 2015 at 20:55 UTC
    Interestingly, !1 is "", ~~(!1) is 0, but ~~("") is "".
    $ perl -MO=Deparse -E'say !1; say ~~(!1); say ~~("");' use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch' +, 'unicode_strings', 'unicode_eval'; say !1; say 0; say ''; -e syntax OK

      Of course. !1 is a dual-value of empty string plus 0. Bitwise operators operate on integers if the scalar has an authoritative ("public") numeric value, otherwise they operate on strings. QED.

      - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found