lua-users home
lua-l archive

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


On Sat, Jul 24, 2010 at 6:20 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> I'm wondering why this is necessary.  Most other languages with a REPL
>> do not require the user to disambiguate expressions and statements.
>
> It is not necessary. The Lua stock interpreter could try first
>        return <user input>
> and then, if that fails, try
>        <user input>
>
> This is almost what it does already, except that it only tries "return ..."
> if the line starts with '='.
>
> The problem with the automatic approach is that you'd get more noise.
> For instance,
>        io.write("Hello")
> would output
>        Hellotrue
> as you can see by entering
>        =io.write("Hello")

Code entered by the user can be classified as an expression,
statement, both, or neither, and the user may want output, not want
output, or not care.  For the first two code types, the desirability
of output is clear.  For the third code type, the norm may be either
wanting output or not caring.  If you really don't want output, you
can suppress it by enclosing the code in a "do .. end".  That case may
be rare in a REPL--e.g. I think `print`, which like a REPL is more
intended for debugging and which has no return values, is much more
common that io.write.  When the code is invalid, I'm not sure which
error message (expression or statement evaluation) should be
displayed.  Perhaps the one that gets furthest along in the token
stream would be ideal, but a difficulty is that Lua currently doesn't
include column numbers in parser error messages (which at times I've
thought it should--like it would be of some use to me in LuaInspect).