Re: Order of operations (was: Eigenvalues &/or eigenvectors,
Re: Order of operations (was: Eigenvalues &/or eigenvectors,
- Subject: Re: Order of operations (was: Eigenvalues &/or eigenvectors,
- From: email@hidden (Michael Sullivan)
- Date: Mon, 12 May 2003 18:12:58 -0400
- Organization: Business Card Express
>
On 5/12/03 12:28 PM, "Michael Sullivan" <email@hidden> wrote:
>
>
> With explicit numbers, I will concede that your interpretation is at
>
> least as reasonable as mine (which would be that -3^2 is to be read as:
>
> - (3)^2).
>
>
>
> But not with variables.
>
>
>
> If I write -x^2, I expect the result to be a *negative* number.
>
>
>
> But applescript doesn't:
>
>
>
> set foo to 3
>
> -foo ^ 2
>
>
>
> --> 9.0
>
>
>
> Sorry, but that's just wrong.
>
No it isn't. It makes perfect sense to me. Whether foo itself is a positive
>
or negative number, -foo is the opposite sign - negative or positive number
>
respectively , so squaring either foo or -foo yields a positive number, just
>
as for the signed integer represented by the variable x. Cubing it would
>
give it the same sign as the integer being cubed (foo or -foo).
It may be clear to you, but it is absolutely *not* what I'd expect after
studying algebraic expressions for years.
>
This is _especially_ clear in the version you've pasted, where there are
>
spaces on either side of the ^ symbol, so that the - sign is clearly
>
attached to just the variable foo and not to the whole expression.
That's what happens when I post the code directly from script debugger
-- because the as parser put those spaces in. I'd almost agree, if I'd
typed it that way originally, that this interpretation makes sense
(since AS is trying to act like a natural language and read intent).
>
If you don't like AppleScript's method, just use parentheses and stop
>
complaining about it.
oh? That's certainly what I intend to do from here. One is not allowed
a rant?
I restate:
>
> If I write -x^2, I expect the result to be a *negative* number.
Do you really expect "-x^2" to be a positive number? Would you really
expect to have to write -(x^2) as the answer to an algebra problem?
I wouldn't. And for that reason, I wouldn't expect to write it in a
programming language that claims to use algebraic order of precedence
either. I find that annoying. Shoot me.
Michael
_______________________________________________
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.