lua-users home
lua-l archive

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


Rici Lake wrote:

On 17-Aug-05, at 1:20 PM, Chris Marrin wrote:

I see it most often for "standard" things like Math.


Indeed. I think math (not Math :) ) might be an exception here, since you're probably not going to find sin, atan2 and PI [1] in other packages (barring a multi-precision mathematics package, of course.)

I actually meant Math, as in the Javascript Math object which has a PI constant :-)


One of the changes between Lua 4 and Lua 5 was the move of a huge number of standard library functions from the global namespace into package tables. On the whole, it's probably an improvement, since it avoids name collision (the common alternative, often found in C programs, is namespacing with prefixes: math_sin, bignum_sin, mortal_sin, etc.; which can hardly be said to be an improvement on math.sin, etc.)

But for casual users, particularly mathematical ones, it's annoying. So one option is to dump the relevant package directly into the global namespace, pretty much as you suggest. But I don't think the proposed 'import' compile-time macro should be overloaded to do this; that's just confusing. (I'm really putting the cart before the horse here, since import is just a nebulous proposal based on an interesting but not yet adopted parsing modification.)

To be clear, I am suggesting they be placed in the local namespace, as set by setfenv(). I don't like the idea of polluting the global namespace.

--
chris marrin                ,""$,
chris@marrin.com          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'