lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Fri, Apr 17, 2009 at 5:16 PM, Peter Cawley <lua@corsix.org> wrote:
On Fri, Apr 17, 2009 at 5:07 PM, Marco Antonio Abreu
<mabreu.ti@gmail.com> wrote:
> Hi Linker.
> You have to attend that the AND operator has a higher priority than the OR
> one. So, "1 or false and true or false" is correct when resulting 1.

"1 or false and true or false" should be interpreted as "(1 or false)
and (true or false)", which should evaluate to "(1) and (true)", which
should evaluate to "true", not "1" ("The conjunction operator *and*
returns its first argument if this value is *false* or *nil*;
otherwise, *and* returns its second argument" - Lua manual).

The Lua manual also details operator precedences in section 2.5.6 - "or" has the lowest precedence, just lower than "and". So "1 or false and true or false" in fact gets interpreted as "1 or (false and true) or false".