lua-users home
lua-l archive

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


On Thu, Sep 28, 2006 at 10:34:00PM +0200, Mike Pall wrote:
>   local userops = {
>     PI =     { arity = 0, op = math.pi }, -- arity 0 are constants
>     sin =    { arity = 1, op = math.sin },
>     cos =    { arity = 1, op = math.cos },
>     ["|"] =  { arity = 2, op = bit.bor },
>     ["<<"] = { arity = 2, op = bit.lshift },
>     ["//"] = { arity = 2, op = function(a, b) return math.floor(a/b) end },
>   } -- These should of course better be light functions.
> 
>   loadstring([[
>     local a, b = ...
> 
>     print( PI * sin a + cos b )
>     print( (a << 11) | (b << 3) | 5 )
>     print( "Rici buys", 1.38 // 0.16, "apples." )

Intuitively, I don't like this.  I don't want to use a language where people
are almost defining their own syntax inside the language.  That takes
the evils that operator overloading can cause in C++ (people using operators
for things unrelated to their original cause, like overriding + for "set
union"), and makes it an order of magnitude worse, allowing making whole
new operators.

That's not to say it couldn't be used well, just like operator overloading
can be used well; it just seems to invite incredible abuse.  Practical
languages can't make it impossible to write bad code, of course--people
will--but this seems at such a level that in order to read anyone else's
code, I'm going to have to learn their own personal sub-language first.

(I don't understand how a parser could support this, since the language
is being defined by the language being compiled.)

-- 
Glenn Maynard