Macros will come to Scala in 2.10. Here’s a quote from the proposal
Compile-time metaprogramming has been recognized as a valuable tool for enabling such programming techniques as:
- Language virtualization (overloading/overriding semantics of the original programming language to enable deep embedding of DSLs),
- Program reification (providing programs with means to inspect their own code),
- Self-optimization (self-application of domain-specific optimizations based on program reification),
- Algorithmic program construction (generation of code that is tedious to write with the abstractions supported by a programming language).
An example of algorithmic program construction in action can be found in Slick (database access framework) in direct embedding mode.
Like implicit conversions, macros should be used with care as they have the potential to make code obscure. Code changes effected by macros are not immediately visible to the programmer, just as implicit conversions can make method invocations hard to track. Both mechanisms can affect code “at a distance”; without proper discipline this can lead to confusion.