[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: chunks and expressions
- From: "Wim Couwenberg" <w.couwenberg@...>
- Date: Thu, 16 Jan 2003 13:59:00 +0100
first of all let me say that I'm extremely pleased with Lua. (I don't even
use Python anymore :-) Though at the moment I do most of my development in
Lua4 (and C/C++) the experiments with Lua5 look promising. Now I have a
question (or suggestion):
Would it be possible (well, feasible actually) to turn a "chunk", "block"
and possibly other statements, all into an "exp"? As a general rule, the
result of a chunk, block or statement would then be the result of the last
evaluated expression within that chunk, block or statement (possibly just
before a "break" in a chunk.) For repeating statements like "for", "while"
and "repeat" the value should probably be the value of the last executed
block. The assignment could be turned into an expression that results in
the assigned value list (or just nil if such a thing would not be possible.)
1. x, y = f() --> values of x, y
2. <epx1> <exp2> ... <expn> --> result(s) of <expn>
3. if a then b else c end --> b or c, depending on a (note that this
differs from "a and b or c" !)
4. do local x <some computations> x end --> value of x
This would certainly have its advantages in places where a conditional
expression is expected, such as in the "if", "while" and "repeat ... until"
6. if do local x <some computations> x end then ... else ... end
7. while a = f:next_line() a ~= "." do ... end
(Yes, there will be an ambiguity between the "do" as the start of a block
and the "do" in "while" and "for" constructions.)
Would it be possible to map such constructs to the _existing_ VM of Lua
already or are there some major obstructions that lead us to make these
distinctions between expressions and statements? How far could we get on
the current VM if we still exclude some statements like repetitions?
Supporting chunks and blocks as expressions would already be something!
I would appreciate it if anyone would give this some thought!