[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: precedence
From: 
John W. Eaton 
Subject: 
Re: precedence 
Date: 
Wed, 7 Aug 2002 02:11:08 0500 
On 6Aug2002, Paul Kienzle <address@hidden> wrote:
 On Tue, Aug 06, 2002 at 12:40:23PM 0500, John W. Eaton wrote:

 > * In Matlab, elementwise AND (&) has higher precedence than
 > elementwise OR (), in Octave they have the same precedence.
 >
 > * In Matlab, shortcircuit AND (&&) has higher precedence than
 > shortcircuit OR (), in Octave they have the same precedence.

 I use parentheses when mixing "and" and "or" in an expression so
 that I don't have to think about precedence, so this won't affect me.

 I believe matlab's precedence corresponds to the usual convention
 in logic so I suppose it is a better choice.

 You might consider warning users if they have mixed "and" and "or" in the
 same expression.
OK, I've checked in a change to the CVS archive that changes the
precedence for , &&, , and & to match Matlab. Octave will now also
warn when expressions like
x  y && z ==> x  (y & z) now, previously (x  y) & z
or
x  y && z ==> x  (y && z) now, previously (x  y) && z
appear. There should be no change if & or && appears first, because
previously, the precedence of & and  was the same, and the precedence
of && and  was the same. Given the left associativity, they would
group the same before as now.
You can turn the warning off by using parens or by setting the new
builtin variable warn_precedence_change to 0 (the default is 1).
The transpose operator precedence fix will take a bit more work.
jwe

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
