lua-users home
lua-l archive

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

On 2013-Oct-15 (Tue) at 05:38 (+0000), Thomas Jericke wrote:

>> There are less theoretical situations where the current
>> implementation is unintuitive. Mostly the 'or' and 'and' operators.
>> They do not only accept non boolean values, they also return
>> non-boolean values. typeof(A or B) could be anything, and 'A' and
>> 'B' don't even have to change their types for "A or B" to change
>> its type.
>> typeof(true or 10) -- boolean
>> typeof(false or 10) -- number


   I suggest that 'and' and 'or' in Lua may feel unintuitive only if
   you expect them to just be the traditional boolean operators.

   But they are much more general than that, while of course including
   the standard behaviour as a particular case.

   This generality may feel weird at first, but once it becomes familiar
   it can be very convenient indeed.


Joseph Manning / Computer Science / UCC Cork Ireland /