From help-octave-request at bevo dot che dot wisc dot edu Wed Aug 7 02:13:27 2002 Subject: Re: precedence From: "John W. Eaton" To: help-octave mailing list Date: Wed, 7 Aug 2002 02:11:08 -0500 On 6-Aug-2002, Paul Kienzle wrote: | On Tue, Aug 06, 2002 at 12:40:23PM -0500, John W. Eaton wrote: | | > * In Matlab, element-wise AND (&) has higher precedence than | > element-wise OR (|), in Octave they have the same precedence. | > | > * In Matlab, short-circuit AND (&&) has higher precedence than | > short-circuit 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 built-in 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 -------------------------------------------------------------