in reply to Re: Re: Re: Operator Precedence (unary negation and exponentiation)
in thread Operator Precedence (unary negation and exponentiation)

Actually I wasn't arguing either of those things (though I insist on my right to hold contradictory opinions!)

I asked why Perl's order of operations does not match my intuition. The answer "negation = subtraction" might explain my failure of intuition but does not explain anything about Perl because Perl does not treat them as the same.

Thank you for the link. The essay made sense - though it still feels counter-intuitive to me.

  • Comment on Re: Re: Re: Re: Operator Precedence (unary negation and exponentiation)

Replies are listed 'Best First'.
Re:^5 Operator Precedence (unary negation and exponentiation)
by pdcawley (Hermit) on Jan 23, 2003 at 04:59 UTC
    One of the most important parts of learning to do maths (and, as a mathematician I could, if pressed, put up a reasonable argument that programming is just another branch of maths) properly is the process of training your intuition -- usually by checking your intuition at the door and working through stuff step by step until you learn why your intuition was correct (or, rarely, incorrect). Probability theory is the classic area where almost every non-trivial result seems counter intuitive.

    Coming back to this particular thing, negation is not quite the same as subtraction, it is a shorthand for it, and there is a right and a wrong time to expand it. For instance, it's perfectly valid to write 3 * -2. If Perl didn't treat negation as somehow 'special' then that would be a syntax error.