Is metaprogramming useful?

Brad Anderson brad at dsource.org
Tue Nov 28 06:31:23 PST 2006


Jarrett Billingsley wrote:
> A little off the topic, but not really, as it spins off of the idea of a 
> compiler as an interpreter.  I always thought it would be an interesting 
> exercise to make a language where metaprogramming is not only possible, but 
> nearly as full-featured as the actual code.  That is, templates (or whatever 
> they'd be called, because they'd be far more advanced) would be a script for 
> the compiler, which could even be compiled to bytecode.  The input would be 
> language constructs -- symbols, statements, expressions -- and the output 
> would be code which could then be compiled.  It'd basically be a scriptable 
> compiler.

Poor Lisp.  It just sits there, 50 years old, debugged, optimized, and ready
to go, while the imperative languages try to inch closer over the decades.

So OOP comes along.  Lisp adds it (in a superior way, imo)
So AOP is (or will be) hot.  Lisp adds it.
Metaprogramming?  The MetaObject Protocol appears, to complement the already
amazing macro facility.

I'm not knocking the imperative languages, as a lot of people know them and
use them successfully.  I am more amazed at how such a valuable toolset is
consistently under-used and its functionality is rewritten from scratch.

As this thread talks about metaprogramming and syntax, the elegance of Lisp's
code being the same as its data is relevant.  To be the ultimate expression of
metaprogramming in this way, you cannot do it in a new language.  You'd end up
merely with another flavor/dialect of Lisp.

Greenspun's 10th Rule of Programming:  Any sufficiently complicated C or
Fortran program contains an ad hoc, informally-specified, bug-ridden, slow
implementation of half of Common Lisp.

BA

P.S.  Please no ignorant replies about Lisp is interpreted or Lisp is slower
than the imperative languages.



More information about the Digitalmars-d mailing list