Metaprogramming and Macros

Explore Metaprogramming and Macros in Scala, including Mastering Metaprogramming in Scala 3: Inline Functions, Macros, and More and Metaprogramming in Scala 2: Mastering Compile-Time Code Generation with Macros.

This section covers the part of Scala that lets code participate in code generation and compile-time transformation. The key distinction is historical as well as technical: Scala 2 macros and Scala 3 metaprogramming solve related problems, but they differ significantly in ergonomics, tooling, and maintainability.

Read these pages if you work on libraries, code generation, DSLs, or compile-time validation and need to understand where metaprogramming helps versus where plain types, inline methods, or ordinary runtime code are enough. Most application code should use metaprogramming sparingly.

In this section

Revised on Thursday, April 23, 2026