lua-users home
lua-l archive

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


On Thu, 2007-04-12 at 19:01 -0400, Glenn Maynard wrote:
> I'd want no separate metamethods for these; it encourages inconsistent
> behavior between the + and += operators.  No separate metamethods means
> I can read code using addition in both forms without having to keep checking
> whether they're actually the same operation, and it means the feature has
> no impact on the VM.

Erm, plus and plus-equals are intrinsically different operations.

a = a + b

=> a = add(a, b)

a += b

=> a:increment(b)

as it were.

Not least of which, "a = b + c" and "b += c" are very *VERY* different
statements.

Think now, not of numbers, but of tables, objects, userdata... Now they
need separate metamethods for the increment/decrement mutation
operators.

If you start adding += and -=, then what about ++ and -- which between
them will add another four metamethods {pre,post}{inc,dec}rement

What you see as a convenient shorthand for a = a + b, I see as an
incredibly scattered minefield of doom where conflation between mutation
and simple arithmetic will cause terrible pain for all those who enter
it.

Now, Asko's idea of token filters would mean that you could have a
personal syntax which you like, which you *understand* to be limited in
the ways that it is limited, and yet you *could* with minimal effort,
use the token filter you had written to write a tool which translates
your lua into standard lua for inclusion in any distributed library or
similar.

D.

-- 
Daniel Silverstone                         http://www.digital-scurf.org/
PGP mail accepted and encouraged.            Key Id: 2BC8 4016 2068 7895