Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: The mystery of double negation

by hurricup (Pilgrim)
on Jul 12, 2015 at 17:34 UTC ( #1134404=note: print w/replies, xml ) Need Help??


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

Nope, it's bitwise negation and doesn't work this way. It's basically - noop. Keeps value the same.

Replies are listed 'Best First'.
Re^3: The mystery of double negation (bool 0)
by tye (Sage) on Jul 12, 2015 at 22:51 UTC
    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        

      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        

Re^3: The mystery of double negation
by shmem (Chancellor) on Jul 12, 2015 at 17:41 UTC

    Right you are. Then... maybe chromatic can enlighten us?

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^3: The mystery of double negation
by Laurent_R (Canon) on Jul 12, 2015 at 18:01 UTC
    You're right, but, still, ~~1 will return 1, i.e a true value. Why the author of the module did that, I have no idea.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-05-17 18:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?