I agree. I think all statements should return values. That is a very powerful feature I'd like to see in Lua. Scheme, for example, has such a concept.
On Thursday, January 11, 2001, at 12:41 PM, Lenny Palozzi wrote:
> In the code below I would like to assign 'c' the return value of function
> 'f', and have c(or the return value of function 'f') compared to the
> right-hand side. From the looks of the Lua syntax, you can't do this in Lua.
> I get:
> error: `)' expected;
> last token read: `=' at line 6 in file `t2.lua'
> Can Lua be easily changed to handle this? Just curious, as I sometimes write
> similar code in C.
> function f()
> return 1
> while (c=f()) == 1 do
> I agree. I think all statements should return values. That is a very powerful feature I'd like to see in Lua. Scheme, for example, has such a concept.
Moreover, statements should be first class: code in blocks like this:
should just be sugar for tables:
(an alternative syntax could be as for tables but without the commas,
sugared in the same way as semicolons in normal code).
This would allow blocks of code to be passed around and altered as in Lisp,
REBOL, Scheme &c.
The only problem I see is that it looks as though it's necessary to
recompile a block every time it's executed in case it's changed; in
practice, though, you can maintain two flags: one saying whether it's
compiled, and another saying whether it's changed. Or even, if you want to
avoid checking a flag every time you execute a block, you could have a
"const"-like specifier so that some blocks of code are compiled
once-and-for-all. You could have a convention that conventional code blocks,
like those between do...end, were constant, whereas code written as tables
could be dynamic. Anyway, these are problems solved by Lisp and Scheme, so
there's no killer problem here.
This gives Lua proper data == code.
http://sc3d.org/rrt/ | egrep, n. a bird that debugs bison