Re: Very strange dates - BUG
Re: Very strange dates - BUG
- Subject: Re: Very strange dates - BUG
- From: "Dennis W. Manasco" <email@hidden>
- Date: Fri, 31 Jan 2003 05:17:01 -0600
At 9:31 pm +0100 1/30/03, Thomas wrote:
That is clearly a bug, -2^2 should return -4 of course.
NO.
Unary minus always takes precedence. (At least in any language I have
ever studied.)
Thus -2^2 is equivalent to (-2)^2.
The Standard Rules of Precedence (as best I remember them):
1. Unary minus
2. Power (^)
3. Multiplication and division (which have equivalent precedence -->
beware if you don't understand both equivalence and the localized
order of evaluation...).
4. Everything else may be arbitrary, undefined, illogical or just
plain confusing.
The moral is:
If you have the slightest doubt about the evaluation of a function
_use parentheses_; they don't take much time, they provide
documentation for those who must later follow your code and they give
explicit instructions to the compiler or interpreter.
Question:
How is the following interpreted ?
-a*b+c*d/e-f^g/h+i*j/k
Answer:
It's a trick question. Even if you look up all of the precedence
rules for the language you are working with you can't give a
definitive answer. You still have to know whether the
implementation-dependant compiler/interpreter is evaluating the
equivalent expressions from left-to-right or right-to-left. Sometimes
even this isn't enough; sub-evaluations may change direction.
Take some pro-active steps to make your equations non-arbitrary. You
won't confuse yourself if you have to read your code later and the
parser will give you unambiguous results.
=-Dennis
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.