Skip to content
0:00 / 0:00

#racket#hygienicmacros#macroexpansion

"Let's Build a Hygienic Macro Expander" by Matthew Flatt

Strange Loop Conference

88K subscribers • 107 videos on Hallway • Conference channel

YouTube
  • Recommended by 3 people: 2 in engineering communities and 1 curated list.
  • A classic. People kept recommending it from 2018 to 2023.
  • Presented by Matthew Flatt

Advanced. Deep dive for people who know the field.

10K views10 years ago3 recommendations

Programming languagesComputer scienceLanguage design and type systemsCompilers and interpretersLisp and Clojure

Matthew Flatt explains the mechanics of hygienic macro expansion using a scope-sets model and walks through its implementation.

Although the idea of hygienic macro expansion appeals to many programmers, the details of hygienic expansion have scared away many language implementors. In fact, in the same way that lexical scope used to seem exotic and difficult to implement compared to dynamic scope---at least, until its implementation via closures became widely understood---the extra dimension of "macro scope" can seem mysterious. Historically, dynamic scope seemed obvious, because it involves a linear sequence of bindings, while lexical scope demands an implementation that matches the two-dimensional nature of nested expressions. Macro scope demands yet another dimension to binding. This talk aims to dispel the mystery of hygienic expansion: first, through a new explanation of macro scope based on "scopes sets"; and second, by walking through the implementation of a macro expansion using scope-sets.

Why it's here

3 people recommend this

What people say. Recommended as an excellent resource for understanding and implementing hygienic macro systems in programming languages.

u/theindigamerin r/ProgrammingLanguages • Recommends

"Let's build a hygienic macro expander" by Matthew Flatt StrangeLoop 2016

u/lyhokiayulain r/ProgrammingLanguages • Recommends

Resources on statically typed hygenic macros? Hello, I'm trying to add macro system to my language. I want it to be as close to racket's system(there's a great talk by Matthew link to this video here talking about the implementation system), but for statically typed language. I know there's quite a few languages that have macro system, but which of them is the easiest to learn? (By that I mean I don't have to learn the language itself before learning anything else, like in Haskell). Thanks!

programming-talkscurated list on GitHubRecommends

Under “Programming Language Design”

Let's Build a Hygienic Macro Expander 00:40:04 by **Matthew Flatt** (2016)

u/davidchristiansenin r/ProgrammingLanguages • Mentions

On “Functional Programming in Lean - an in-progress book on using the Lean theorem prover to write programs”

A macro is a local source-to-source transformation. For instance, a language without `let` could get it with the following (pseudocode) macro that expresses it as a beta redex: macro `(let $x = $def in $expr) = `((fun $x => $expr) $def) Here, `let` is the macro, and the beta redex is referred to as the _expansion_. The backtick and dollar notation is intended to be quasiquotation, so the bits under a backtick are quoted syntax but the dollar escapes back to usual pattern or evaluated context. Macros have a long tradition in the Lisp world. One of the big advances in macros was the notion of _hygiene_, which means that names introduced in the expansion neither capture nor are captured…