This page briefly discusses well-known prior art on metaprogramming in various programming languages. Template Haskell may be the most directly relevant piece of software to consider.
Template Haskell implements type-safe metaprogramming in a strongly, statically typed language. Allows you to do neat-o stuff like compile-time I/O, among other things. Essentially presents to the programmer a strongly-typed syntax tree that can be programmatically manipulated. Its homepage has research papers on it.
MetaOCaml focuses on multi-stage programming. The distribution you can download includes interesting examples of speeding up numerical calculations by substituting constants only available at runtime for variables and other forms of optimizations. Its homepage has research papers on it.
Often considered to have the most powerful (and potentially dangerous) macro system. Its macro system is available at readtime, compile-time, and runtime. Pitfalls include things like variable capture. To see what Lisp’s macros can do, read Paul Graham’s On Lisp (which is considered to be one of the best programming books ever published, so you should read it even if you aren’t interested in macrology). See also Norvig’s famous PAIP for another perspective on them.
The Common Lisp Object System MetaObject Protocol, or CLOS MOP, provides some prior art to study in consideration for how Scala might offer similar capabilities. For instance, we’ve recently been discussing how to model “properties” for inspection, be it through reflection or some other MOP-like facility. The CLOS MOP offers the compute-slots function that provides the slots (or “properties” if you like) of a metaclass.
Slot definitions are first-class objects themselves. In the discussion of Initialization of Slot Definition Metaobjects, one can use generic functions such as slot-definition-readers to, say, access the set of functions that allow one to read a slot value.
Scheme uses hygienic macros to avoid some of the pitfalls associated with Lisp’s macro system.
Python supports metaprogramming through metaclasses, descriptors, and decorators. Metaclasses enable the creation of new “types of classes” which can customize the class creation process and/or add class methods and attributes. Descriptors provide a very concise way to add custom properties to classes that invoke logic but syntactically manipulated as regular attributes. They can also carry extra information (such as titles, database column mappings, etc) that can be useful when accessed through relfection. Decorators look like Scala annotations but are applied only to function definitions and yield (possibly transformed) functions. Python also supports code-generation via the “eval” function, but it is rarely used and code generation is widely considered “un-Pythonic.”
Boo supports syntactic macros and meta methods.