[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Table dot number?
- From: David Hollander <dhllndr@...>
- Date: Sat, 29 Oct 2011 22:52:08 -0500
> In my case, it was to allow illegal characters in a function name, such as ["Check?"].
> I did similar once to allow @ and $ in identifier names,
If Lua doesn't mind taking a page from Scheme\LISP, and allowing non
syntax characters in function names, "?" and "!" are quite useful as
suffixes. Even if the number of builtin syntactical operators are
expanded in the future, one could patch their code with a quick grep.
I suppose there could be a readability counter argument, as Python
currently also disallows ! and ? in names.
On Sat, Oct 29, 2011 at 12:51 AM, HyperHacker <firstname.lastname@example.org> wrote:
> On Fri, Oct 28, 2011 at 20:02, Tom N Harris <email@example.com> wrote:
>> On 10/28/2011 04:09 AM, HyperHacker wrote:
>>> This has bit me a few times, when writing functions to parse other
>>> function funcs.foo(...) doThings() end --OK!
>>> function funcs.for(...) doStuff() end --Invalid!
>>> function funcs['for']() doStuff() end --Also invalid! (a function
>>> can't be defined using this syntax)
>>> The only way is to write:
>>> funcs['for'] = function(...) doStuff() end --OK, but harder to read,
>>> especially alongside those like the first line.
>>> Could these restrictions not be lifted? An expression such as [[
>>> blah.for i = 1,5 ]] wouldn't be syntactically valid, so there doesn't
>>> appear to be any ambiguity to worry about. Especially I don't
>>> understand why line 3 isn't acceptable.
>> I patched the parser to read NAME as a 'namelit' which is parsed as:
>> namelit -> NAME | reserved word | '[' String ']'
>> In my case, it was to allow illegal characters in a function name, such as
>> This is just coddling coders who don't want to type _G["Check?"] =
>> function(...) end. Well, you can also use it for locals, but then we're
>> encouraging bad habits. So I would not want to see it become part of Lua. Or
>> at least, don't accept reserved words.
>> - tom
> I did similar once to allow @ and $ in identifier names, with the
> intention that they be used for special cases. I don't think I ever
> submitted that patch anywhere, but it's fairly trivial to do...
> Sent from my toaster.