lua-users home
lua-l archive

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

Michael T. Richter wrote:
Of concern to me would be to avoid the Dylan trap of making the macro
system fundamentally a different language from the core language.
Dylan's macro system was Lisp-like in structure (since Dylan started as
a Lisp derivative and only inherited a more conventional syntax later
on).  There was talk about moving the macro system into a syntax that
more closely matched the core language, but the project got killed at
Apple before that could happen and the language died a gruesome death
after that.  I'm not convinced that the conversion could happen, though.
I think there's a reason why hygenic macros seem to only show up in
languages that basically don't have a syntax.  ;-)

True, true. OTOH, with Lua's scoping, hygiene would be an emergent property of a simple pattern/template preprocessor. Admittedly it wouldn't have the full power of a traditional example system, but it'd be pretty easy to implement. Represent macros as pairs of a Lua standard pattern string and either a replacement string or a function that transmutes the pattern into the source code that implements it. Store these in a table. Then hijack every function that loads code so it reads it itself, runs string.gsub on the source against every pair in the macro table until no further substitutions occur, then finally does whatever would have been done with the code originally.

I'm tempted to implement it myself later on today.