lua-users home
lua-l archive

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

On Thu, Jun 30, 2011 at 1:42 PM, Oscar Chinellato
<> wrote:
> This is exactly why I would appreciate the __assign metamethod - it's
> non-intrusive (existing code would behave exactly the same) and,
> assuming that the programmer does a good job, it's safe.

I can see one problem with __assign; it means that every assignment
needs a metatable check. That would probably slow things down for all
programs. And you'd have to do it as well for values passed as
function arguments.

Having survived C++, I must say that 'overloading the assignment
operator' leads to 'subtleties' (as Stroustrup puts it in his
restrained way)   It makes programs harder to understand, because of
the increasingly paranoid feeling you get that the programmer is doing
something _clever_ in the simplest of statements.

In the context of a DSL meant to be used by numerical people[1], then
sure. The restriction to a domain means that object behaviour can be

So either a patch or some preprocessor?  I was entertaining myself the
other day with this kind of macro-ized syntax:

    $> luam  -llist -i
    Lua 5.1.4  Copyright (C) 1994-2008, PUC-Rio
    Lua Macro 2.3.0 Copyright (C) 2007-2011 Steve Donovan
    > list a = {'one','two'}
    > = a:map(\x(x:sub(1,1)))
    > a:append 'three'
    > a:append 'four'
    > = a
    > = a[2:3]
    > = a[2:2] = {'zwei','twee'}
    > = a[1:2]..{'five'}

It's amazing what you can do with a little bit of lexical look-ahead...

steve d.
[1] this set definitely does not include Dirk, of course