http://qs1969.pair.com?node_id=1134404


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.