Scala 3 Macro Tutorial

Scala 3 Macro Tutorial

  • Tutorial
  • Contribute
  • GitHub

›Tutorial

Tutorial

  • Introduction
  • Inline
  • Scala Compile-time Operations
  • Scala 3 Macros
  • Quoted Code
  • TASTy Reflection

Extra

  • FAQ
  • Best Practices
  • Other Recources
Edit

Introduction

This tutorial covers all the features involved in writing macros in Scala 3.

The metaprogramming API of Scala 3 is designed in layers to gradually support different levels of use-cases. Each successive layer exposes additional abstractions and offers more fine-grained control.

  • As a starting point, the new inline feature allows some abstractions (values and methods) to be marked as statically reducible. It provides the entry point for macros and other metaprogramming utilities.

  • Compile-time operations offer additional metaprogramming utilities that can be used within inline methods (for example to improve error reporting), without having to define a macro.

  • Starting from inline-methods, macros are programs that explicitly operate on programs.

    • Macros can be defined in terms of a high-level API of quoted expressions, that admits simple construction and deconstruction of programs expressions.

    • Macros can also be defined in terms of a more low-level API of TASTy Reflection, that allows detailed inspection of programs.

🚧 We are still in the process of writing the tutorial. You can help us improve it 🚧

Inline →
Scala 3 Macro Tutorial
Docs
TutorialContributeFAQ
Community
Chat on GitterDiscuss on Scala Users
More
GitHub
Copyright © 2020 LAMP EPFL