Quasiquotes

Terminology summary

Language
This doc page is specific to features shipped in Scala 2, which have either been removed in Scala 3 or replaced by an alternative. Unless otherwise stated, all the code examples in this page assume you are using Scala 2.

EXPERIMENTAL

  • Quasiquote (not quasi-quote) can refer to either the quasiquote library or any usage of one of its interpolators. The name is not hyphenated for the sake of consistency with implementations of the same concept in other languages (e.g. Scheme and Racket, Haskell)
  • Tree or AST (Abstract Syntax Tree) is a representation of a Scala program or a part of it through means of the Scala reflection API’s Tree type.
  • Tree construction refers to usages of quasiquotes as expressions to represent creation of new tree values.
  • Tree deconstruction refers to usages of quasiquotes as patterns to structurally tear apart trees.
  • Unquoting is a way of either putting things in or extracting things out of quasiquotes. Can be performed with $ syntax within a quasiquote.
  • Unquote splicing (or just splicing) is another form of unquoting that flattens contents of the unquotee into a tree. Can be performed with either ..$ or ...$ syntax.
  • Rank is a degree of flattening of unquotee: rank($) == 0, rank(..$) == 1, rank(...$) == 2.
  • Lifting is a way to unquote non-tree values and transform them into trees with the help of the Liftable typeclass.
  • Unlifting is a way to unquote non-tree values out of quasiquote patterns with the help of the Unliftable typeclass.

Contributors to this page: