lua-users home
lua-l archive

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


On Thursday, June 18, 2015 11:08:39 PM Dirk Laurie wrote:
> None of these is quirky or a corner case. All behave exactly as documented.

The description isn't even strictly correct. Not only expressions are printed. 
"math.random();" is a statement that is printed. (Because of course it's not 
checking if the input is an expression but rather can the input be compiled 
with "return " prepended.)

When a statement has an open parenthesis or long-string or table constructor, 
you can fix it by adding the closing token and be on your way. Why not do the 
same for expressions? What utility is gained by not allowing multi-line 
expressions? What utility is lost by having them? All I see are shortcomings, 
such as not being able to type a string with a newline in it.

If "because that's not what the manual says" were a good enough reason we'd 
never have expressions in interactive mode. It was simpler then, even if our 
pinky fingers would be exercised pressing '=' so often. But I never had a 
problem with that. Lone expressions are not valid syntax so it made sense not 
to accept them.

Having expressions lets Lua act more like a desk calculator. But then the 
legacy restrictions on statement-versus-expression act as a stumbling block 
when you're typing an expression and either forget a parenthesis or want to 
break it into multiple lines to be easier to read.

You can still use the '=' shortcut, but that has been omitted from the 5.3 
manual, I presume to indicate that it is deprecated. But if Lua is never going 
to allow multi-line expressions in interactive mode, then I'd prefer the '=' 
shortcut remain as a supported feature.

Or go back to the old statements-only interpreter and if you want a full-
featured interactive mode you can install luaprompt, which does handle multi-
line expressions. (Well, almost. It won't continue "1 +".)

-- 
tom <telliamed@whoopdedo.org>