[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Inline Functions
- From: "Peter Hill" <corwin@...>
- Date: Tue, 24 Dec 2002 13:17:10 -0000
> (btw. it is pretty cool that "Complete Syntax of Lua" fits on one page on
> the manual)
I absolutely agree!
These days there seems to be an illusion that powerful & clear languages
need a really complex syntax =:-O. But that's just not true! And if one
wants to make programming available to the casual user (vs coder) ...
something that I believe will become more-and-more important in the future
(especially now that VCRs etc are being design with operating systems!) ...
then the syntax NEEDS to be simple.
Tradionally, end users have always been lumped with some kludgy half-baked
little "macro" language. Historically, Lua was created to redress that
injustice, being a powerful & clean inline language. About time! :-)
Peter Hill wrote:
> one should be able to write:
> function (a) print("a="..a) end (123)
> however this doesn't work in Lua4.0. Does it work in Lua5.0?
> It does not, but
> ( function (a) print ("a="..a) end ) (123)
> Looking at the "Complete Syntax of Lua" this is just as it should be. You
> need the extra parenthesis in order to convert from "exp" to "prefixexp".
So I see:
prefixexp ::= var | functioncall | '(' exp ')'
But, at a glance, I can't see why one could not just include "function" in
there as well.
prefixexp ::= var | function | functioncall | '(' exp ')'
It makes strong sense to have it as a "prefixexp" (what could be more of a
function than "funtion () ... end" itself!) and, as it forms a nicely
wrapped unit, I don't forsee any syntax problems.
I official petiton its addition! *grin*
I notice in the manual that the "free format" of Lua fails in one situation:
"As an exception to the format-free syntax of Lua, you cannot put a line
break before the ( in a function call. That restriction avoids some
ambiguities in the language."
In essence, it is a situation where an expression doesn't know whether or
not to stop gathering terms.
A similar situation occurs with "return":
Currently "return" is prevented from grabbing extra arguments by wrapping it
in a "do ... end" (something which is *not* shown on the syntax diagram!)
but, with this new syntax ruling, perhaps "return" should simply follow the
Note that not all the arguments would need to be on the one line so long as
a comma was included to show that the arguments continued. Eg: