Quotes and Splices
Code as data.
Code as Data
Scala 3 metaprogramming treats code as data. A quote captures a piece of code as an Expr, and a splice inserts an Expr back into code.
The Quote: '{ ... }
'{ expr } turns an expression into an Expr[T]. The code is not run — it becomes a value the macro can manipulate.
import scala.quoted.*
def greeting(using Quotes): Expr[String] = '{ "Hello, " + "world" }All lessons in this course
- Inline Methods
- Macros Basics
- Quotes and Splices
- Practical Macros