Macros are a form of compile time metaprogramming. Certain elements of Scala code, such as annotations and methods, can be made to transform other code when they are compiled. Macros are ordinary Scala code that operate on data types that represent other code. The [Macro Paradise] plugin extends the abilities of macros beyond the base language. [Macro Paradise]: http://docs.scala-lang.org/overviews/macros/paradise.html
- def x() = macro x_impl // x is a macro, where x_impl is used to transform code
- def macroTransform(annottees: Any*): Any = macro impl // Use in annotations to make them macros
Macros are a language feature that need to be enabled, either by importing
scala.language.macros or with the compiler option
-language:macros. Only macro definitions require this; code that uses macros need not do it.