0PricingLogin
Scala for Backend Engineering & Functional Programming · Lesson

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

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