lua-users home
lua-l archive

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


On May 18, 2014, at 2:31 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

> Field names must not be global variables or start with underscore.
> 
> Lua 5.3.0 (work2)  Copyright (C) 1994-2014 Lua.org, PUC-Rio
>> require"query"
> Query hack enabled
>> a={b={c={d={e='bazinga'}}}}
>> a/b/c/d/e
> bazinga

That _ENV hack is a lot like perl barewords [1]: 

    "[without use strict...] a bareword is treated as if quotes were around it."

An interesting use of your syntax might be lexical overrides inside a module. Let's say I wanted "string.sub" to always mean "string.utf8sub" in my code, but not affect anyone else:

    local _ENV= [...]
    _ENV.sub = "utf8sub"

    v = string/sub(s, i, j)

I don't need to use printable names, so I can use fresh ones which can't overlap:

    local function mysub(s,i,j) [...] end
    _ENV.sub = {}
    string[_ENV.sub] = mysub

    v = string/sub(s, i, j)

...except none of that works, since "/" is the wrong precedence. But those are just warmups; the real question is how to make something like this work:

    v = s:/sub(i, j)

so we don't have to fight over who owns the string metatable.

Jay

[1]: http://perldoc.perl.org/perlglossary.html#bareword and a starring role in http://perldoc.perl.org/perltrap.html#Perl-Traps : "Avoid barewords if you can, especially all lowercase ones. You can't tell by just looking at it whether a bareword is a function or a string. By using quotes on strings and parentheses on function calls, you won't ever get them confused."