Macros Basics
Compile-time code.
What Is a Macro?
A macro is code that runs at compile time to generate other code. Scala 3 macros let you inspect arguments, build expressions, and emit them into the program before it is compiled.
Inline + Macro Pattern
A macro is invoked from an inline def that delegates to a method marked with ${ ... }. The inline def is the public API; the macro impl runs in the compiler.
import scala.quoted.*
inline def power(x: Double, inline n: Int): Double =
${ powerImpl('x, 'n) }All lessons in this course
- Inline Methods
- Macros Basics
- Quotes and Splices
- Practical Macros