On Fri, 2024-05-03 at 09:23 +0200, bil til wrote:
>
> >Am Mi., 1. Mai 2024 um 17:46 Uhr schrieb 'Gerhard Sittig' via lua-l <
lu...@googlegroups.com>:
> > Yes the lua(1) manpage may need adjustment. It discusses that
> > lines are read, and tried to compile, before execution.
>
> ... btw. this "local own chunk" pecularity is explained in detail and
> very well in Roberto's Book "Programming in Lua", Cahpter 8, "Local
> Variables and Blocks".
You deleted the more important part of what I wrote, the
"statement vs chunk" reference. The full context was:
Yes the lua(1) manpage may need adjustment. It discusses that
lines are read, and tried to compile, before execution. My local
copy talks about "statements" while I think this should read
"chunk" instead. [ ... ]
It's well understood that a REPL interpreter does take input, and
processes it, and may generate output. The very issue discussed
in this thread was that users expected that individual REPL
activities would be "coupled" instead of separate from each
other. They share global state. But local activities in one chunk
would not transpire to other chunks. Which becomes apparent when
looking at the example application's implementation details, but
isn't obvious before becoming aware of these details.
Had a look at more recent sources than the installation which I
was referring to earlier. File lua-5.4.6/doc/lua.1 still reads:
In interactive mode, lua prompts the user, reads lines from
the standard input, and executes them as they are read. If
the line contains an expression, then the line is evaluated
and the result is printed. If a line does not contain a
complete statement, then a secondary prompt is displayed and
lines are read until a complete statement is formed or a
syntax error is found.
Can't tell "how much Zen" is in the question of whether a "do ...
end" block is "a statement". Granted it's a compound statement.
Which happens to include several other statements in its body.
The missing information is the execution in separate chunks, as
soon as the input text "gets committed" (full line) and compiles
successfully. Such a chunk can be more than one statement (see
earlier examples in the thread).
The point remains: Passing one script to the runtime which is
taken as one chunk, and passing several pieces of input to the
REPL interpreter, which processes them in separate chunks that
don't share local context, makes the difference here.
The question is how the documentation that ships with the lua(1)
application can communicate that detail to its users. Referencing
"external literature" like the Blue PiL can be perfectly
acceptable, as long as users have the chance to know, or learn.
It's important to remain aware that the PiL is not an integral
part of the distribution of the Lua reference implementation. Two
editions exist, targetting 5.0 and 5.3 respectively. The PiL
doesn't ship with the interpreter, and its content may disagree
with the interpreter's and runtime's versions that users have.
That's fine, since the PiL is considered an independent external
thing. That's why I wouldn't consider it to be _the_
documentation that users own or have access to, and must know.
Another option is to not assume PiL awareness at the user's, and
reference a FAQ. It's a known pitfall and the solution is also
known (drop the 'local' decoration, or create wider scopes).
Some users still use the (free) online version which discusses
5.0 when they run local installations that are 5.3 or 5.4. That's
fine as long as they do the translation and adaption on their
side. And me mentioning that PiL is separate and external doesn't
mean that it should come for free or needs to be part of the
distribution. It's a great read and a valuable resource in
learning the language and mastering embedding et al, and worth
getting anyway when you are serious. This is not a critique.
My point is: How can formerly unexpecting users become aware,
understand the detail, and accept the fact. To then successfully
use the tool and enjoy, knowing it works correctly. How can they
learn that there is no problem without reading the source code.
Is such a phrase considered useful?
Interactively entered source code executes in separate chunks
sharing the same Lua state. Local details are not available to
other chunks.