Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

What Is A Macro

Before looking at macros in detail, it is helpful to build a conceptual model of what macros are and how they fit into the compilation pipeline.

At their core, macros are meta-programming:

  • They take input code (expressed as tokens) and emit output code.
  • They execute during compilation, expanding before type checking and semantic analysis.
  • They allow expressing patterns and abstractions that cannot be written with generics or standard functions.

We will explore how compilers process source code, and how different macro systems hook into this process.

This slide should take about 5 minutes.
  • Ask students if they have used macros in other languages (e.g., C/C++ preprocessor, Lisp, or Clojure).