lua-users home
lua-l archive

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

On Jan 3, 2008 3:40 PM, Fabien <> wrote:
> The boundary between gratuitous syntax tweaks and support for a new paradigm
> is not always obvious to trace (to take a recurring example, would a switch
> statement be carcinogen syntax sugar, or would it substantially improve
> readability?)

It's a delicate balance. Macros were often necessary in C, because it
didn't have inlining and you could get a serious performance increase.
But C macros are not very intelligent, and were applied by people with
'arbitrary tastes'.  So C++ people regard them as the work of the
devil. Lua is naturally fully polymorphic so a lot of the traditional
uses of macros aren't necessary.

Sometimes we have to try out some sugar, to see if it makes our life
easier. A candidate for that is try..except, since it makes a slightly
awkward syntax easier to use. Of course, it conceals the fact that
we're really creating a new closure for each try..except, and that
might bite you in performance-critical code.  So  this kind of macro
makes it easier to evaluate any Lua extension proposals.

Another use case is when implementing a DSL, to make the syntax fit
the domain more tightly. Then we are essentially making a specialized
Lua-based language.

Strangely enough, I am not fully convinced that lua macros are a good
idea ;)  There are far too many Joe Random Hackers around - but on the
other hand, we should be rather restrained by good style than by a
simple 'No you can't do that!

steve d.