lua-users home
lua-l archive

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


> On Jul 16, 2015, at 3:56 PM, Rena <hyperhacker@gmail.com> 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.
> 

For me this is one where clarity wins over terseness. You aren’t getting any run-time benefit, since the logic is just the same. Really this is just saving a tiny bit of typing, but making the language more complex.

—Tim