0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

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

  1. Inline Methods
  2. Macros Basics
  3. Quotes and Splices
  4. Practical Macros
← Back to Scala for Backend Engineering & Functional Programming