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

!0 is not necessarily 1 (was Re: Secret Perl Operators: the boolean list squash operator, x!!)

by merlyn (Sage)
on Aug 01, 2006 at 13:53 UTC ( #564996=note: print w/ replies, xml ) Need Help??


in reply to Secret Perl Operators: the boolean list squash operator, x!!

Until "!0" is documented to return specifically "1" and not just "a true value", your coding is dangerous.

Sure, !0 has been 1 in every implementation of Perl (so far), but there's no doc that supports that. It's merely an artifact of implementation. "!0" could return "4" and still perfectly satisfy all external Perl docs. I see nothing in perldata or perlop to validate that !0 is precisely "1". Just "true".

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


Comment on !0 is not necessarily 1 (was Re: Secret Perl Operators: the boolean list squash operator, x!!)
Re: !0 is not necessarily 1 (was Re: Secret Perl Operators: the boolean list squash operator, x!!)
by Aristotle (Chancellor) on Aug 01, 2006 at 14:23 UTC

    Guess we should tell Larry that his suggestion was dangerous, then…

    Makeshifts last the longest.

Re: !0 is not necessarily 1 (was Re: Secret Perl Operators: the boolean list squash operator, x!!)
by BrowserUk (Pope) on Aug 01, 2006 at 14:46 UTC

    I gotta ask this. If v5.12 arrived with !0 returning 4, and the OP code broke, would the fix be to the OP code, or to v5.12?

    Also, "dangerous" is usually reserved for things that threaten life or limb. Under any circumstance where code could possibly be dangerous in that sense, any such fundemental change to the implementation, documented or not, would surely be detected during the obligatory, extensive system and regression testing that any software in such a life critical application would have to undergo?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: !0 is not necessarily 1 (was Re: Secret Perl Operators: the boolean list squash operator, x!!) (Larry)
by tye (Cardinal) on Aug 01, 2006 at 14:47 UTC

    Quoting elsewhere in this very thread:

    it's mentioned in the Camel, in the "Ideographic Unary Operators" section, page 92:
    Unary ! performs logical negation, that is, "not". See not for a lower precedence version of logical negation. The value of a negated operand is true (1) if the operand is false (numeric 0, string "0", the null string, or undefined) and false ("") if the operand is true.

    So I guess that boat has sailed not just practically (which it did a long, long time ago) but also as far as being officially documented. Larry did have some editorial control over "the Camel", no?

    - tye        

      The camel is a derived text, not an authoritative text, because it's never viewed as "a required doc" for Perl development.

      When the patch is made to perldoc, I'll shut up about my claim. The evidence in the camel is a hint that the perldoc should indeed be patched.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Could you shut yourself up (would you submit the patch)?
Re: !0 is not necessarily 1 (was Re: Secret Perl Operators: the boolean list squash operator, x!!)
by ikegami (Pope) on Aug 01, 2006 at 15:00 UTC
    At this point, it's used as much as documentated features. Larry and the developers wouldn't change the value of true without taking that into consideration. They'd need an aweful good reason to change it. In addition, isn't there a mantra to the effect of "Perl is what perl does"?
      In addition, isn't there a mantra to the effect of "Perl is what perl does"?

      If so, it's a bad mantra. People can't ever legitimately claim to know how to program in Perl if the definition of Perl changes with each daily build.

      If Larry replaces perl.c with hello.c, does "Hello, World" become the new Perl? ;-)

Re: !0 is not necessarily 1 (was Re: Secret Perl Operators: the boolean list squash operator, x!!)
by shmem (Canon) on Aug 01, 2006 at 15:40 UTC
    Sure, !0 has been 1 in every implementation of Perl (so far), but there's no doc that supports that. It's merely an artifact of implementation.
    That artifact of implementation possibly resides in handy.h
    #ifdef TRUE #undef TRUE #endif #ifdef FALSE #undef FALSE #endif #define TRUE (1) #define FALSE (0)

    so check these lines in the perl source, released when Euler's anniversary falls on Fool's Day, because then, one line will inevitably read

    #define TRUE (2.718281525)

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-04-19 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls