lua-users home
lua-l archive

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

This is one of those areas where languages without infix notation, but variable-length arguments (like lisp) smile.  You can just do (< x y z) and it will do what you expect or (< (<x y) z) to simulate the lua behaviour.

But then you have to give up infix notation and/or have crazy conventions like {x < y < z} means to transform to (< x y z) if curly braces are used and every odd symbol is the same.

On Thu, Jul 16, 2015 at 5:56 PM, Rena <> wrote:
This is something I've often wished to have in various languages, and
I accidentally discovered that it's valid syntax in Lua:

if x < y < z then...

Of course, it doesn't actually work, because it evaluates as "(x < y)
< z", and "(x < y)" evaluates to a boolean. (I couldn't find a way to
make clever metamethods that would allow it to work either, since
__le's result is always converted to a boolean, so you lose the values
of x and y.)

(The idea of course is that it evaluates as "x < y and y < z".)

Just something I noticed and thought was interesting.

Sent from my Game Boy.