[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Reserved words as table index names. (Was [ANN] Lua BitOp 1.0.1 released)
- From: "Joseph Stewart" <joseph.stewart@...>
- Date: Wed, 7 Jan 2009 11:35:34 -0500
On Wed, Jan 7, 2009 at 11:28 AM, Mike Panetta <firstname.lastname@example.org>
In C++ any reserved 'word' (are +, -, * etc words?) can be overridden. In ruby they can be overridden as well (despite being told not to ;) as I created an and method in a class and executed the method fine.
The ability to override the basic operations (keywords) supported by a language is one of the keys to true OOP. Most of these things are handled in lua as metatable overrides, maybe we just need more metatable entries for the other operations? If that were the case a userdata or custom table 'type' could use the built in and, or, not etc keywords and do the right thing based on the argument types...
Hrm, if one actually implemented this, it would make the language definable in terms of itself... Now thats crazy!
See forth and io!
I'm honestly not sure what the optimal solution would be. Lua was not designed as a full OO language (nothing wrong with that!), so from a purists point of view there is no room for this kind of thing. On the other hand allowing such constructs won't break anything (well at least the table index constructs) so why not allow them?
On Wed, Jan 7, 2009 at 10:53 AM, Roberto Ierusalimschy <email@example.com>
> Hmm... I wonder how hard it would be to change the parser so that when aAccording to "Programming Ruby", "and" (and "or", "not", etc.) should
> table is being indexed with . or : it acts similar to other languages (such
> as ruby) and interprets everything after the . or : up to the first bit of
> white space explicitly as a name. In ruby (and probably python)
> something.and is legal.
not be used as a method name (2nd edition, p. 328).
A small Python program:
a.x = 4;
a.or = 3;
File "temp", line 2
a.or = 3;
SyntaxError: invalid syntax
And the question is not whether it is easy or hard to change the parser
to allow such names. The question is whether this would be a good
idea. The concept of reserved words has a long tradition in programming
languages, being adopted by most current languages (C, C++, Java, C#,
Python?, Haskell, Erlang, Pascal, etc.)
(BTW, in Erlang both band and bor are reserved ;).