lua-users home
lua-l archive

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


2015-06-18 0:23 GMT+02:00 Tom N Harris <whoopdedo@whoopdedo.org>:
> I see you put a check to not save 'return' in readline history. Cool, thanks.
> But it still doesn't handle expressions in parenthesis.

Correctly so, Open parenthesis as a way to claim the next line as
a continuation is a Python convention. Not Lua.

>
> Lua 5.3.1  Copyright (C) 1994-2015 Lua.org, PUC-Rio
>> (1 +
>>> 1)
>>>
>
> or this should print XY

Not "should". At most "might by some be expected to".

>
> Lua 5.3.1  Copyright (C) 1994-2015 Lua.org, PUC-Rio
>> ("x"..
>>> "y"):upper()
>>

The manual says:

   In interactive mode, Lua repeatedly prompts and waits for a line.
   After reading a line, Lua first try to interpret the line as an expression.
   If it succeeds, it prints its value. Otherwise, it interprets the line as
   a statement. If you write an incomplete statement, the interpreter
   waits for its completion by issuing a different prompt.

It's quite clear: printing the result is only available for a one-line
expression.

In the first example, what you have is an incomplete statement.
Enter a semicolon to force completion and get, correctly, an error
message for the dangling expression.

In the second example, the statement is indeed complete, but
since it is not on one line, the result iss not printed.

> The patch I had previously suggested does not have this flaw.

It is not a flaw. It is a deliberate design decision, since for most
people, if the parentheses on the first line they type in an
interactive session are unbalanced, it is a mistake.