lua-users home
lua-l archive

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

On 20/02/2008, Roberto Ierusalimschy <> wrote:
> > But why is it that keywords cannot be used as names? There are patches
> > etc. around that allow it, and I don't really see the problem with it
> > (but maybe that's just me). Except that you could maybe "hide" certain
> > keywords if you use its name in _G or something, but I'd say that is
> > the programmer's responsibility, like many things in Lua. Isn't the
> > Lua filosophy to not enforce/restrict, but to empower the programmer
> > and assume some measure of common sense?
> Lua uses a quite traditional approach to scanning and parsing. In this
> approach, a reserved word is recognized by the scanner ("lexer") and
> then becomes something as different from an identifier as "+" or ">=".
> Of course we can change Lua to accept things like t.while. But, from
> the point of view of the compiler, this is as weird as accepting t.+
> or t.>= (which also could be actually accepted).
> >From a more practical point of view, accepting these extra
> constructions compromise the robustness of the grammar, that is,
> how it behaves before erroneous input. (I must confess that the
> current robustness is already somewhat low.)

I see, that makes sense. I agree t.+ looks weird, and whether it's
desirable to allow that is debatable. Although, like you said, for the
compiler it makes no difference. Different keywords have different
roles in the grammar. Some keywords are operators, other keywords are
statements, still others are delimiters, etc. They're all called
keywords, but that on itself is not a very useful classifier here, it

For example, "end" (in Lua) and "}" (in C) play a similar role in the
grammar, but one is called a keyword and the other is not. Some
languages have a "mod" operator while others have "%", but their role
is the same. Again one is called a keyword and the other is not. It
becomes confusing when symbols are used as names in Lua, because t.}
and t.% look weird (to a human reader), while t.end and t.mod look

Again, as you said, it makes no difference to the Lua compiler.
Whether this should be exploited or not, I leave for someone else to
decide :-P but I can certainly see the problem with robustness that
you mention.