lua-users home
lua-l archive

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


On 9 July 2010 04:45, Fabien <fleutot+lua@gmail.com> wrote:
> On Fri, Jul 9, 2010 at 12:16 AM, Henk Boom <henk@henk.ca> wrote:
>>
>> IMO explicit declarations are a good thing because they clarify
>> scopes. I would love for all variables would be statically and
>> lexically scoped, so that the compiler could generate compile-time
>> error messages for undeclared variables. That requires that you be
>> able to statically determine module imports, though. (maybe it could
>> be done with metalua)
>
> Not reliably: since require() is a regular function call on a regular global
> var, it can be constructed in arbitrarily complex ways:
> add_r = |x| 'r' .. x
> getfenv()[add_r 'equire'] 'imported_module'
> But rebuilding a dependency graph based on occurrences of global 'require'
> is not difficult, and has already been done, including in at least one
> commercial product.

I was thinking of replacing require with a macro which would declare
static variables for imported names, something like the way PLT-Scheme
does it. It requires that you know what names a serving module
provides when you're compiling the client module though.

    henk