Macros

Use Cases

Language
This doc page is specific to features shipped in Scala 2, which have either been removed in Scala 3 or replaced by an alternative. Unless otherwise stated, all the code examples in this page assume you are using Scala 2.

EXPERIMENTAL

Eugene Burmako

Since their release as an experimental feature of Scala 2.10, macros have brought previously impossible or prohibitively complex things to the realm of possible. Both commercial and research users of Scala use macros to bring their ideas to life. At EPFL we are leveraging macros to power our research. Lightbend also employs macros in a number of projects. Macros are also popular in the community and have already given rise to a number of interesting applications.

The recent talk “What Are Macros Good For?” describes and systemizes uses that macros found among Scala 2.10 users. The thesis of the talk is that macros are good for code generation, static checking and DSLs, illustrated with a number of examples from research and industry.

We have also published a paper in the Scala’13 workshop, “Scala Macros: Let Our Powers Combine!”, covering the state of the art of macrology in Scala 2.10 from a more academic point of view. In the paper we show how the rich syntax and static types of Scala synergize with macros and explore how macros enable new and unique ways to use pre-existing language features.

Contributors to this page: