[PADL'23] Modern Macros

[PADL'23] Modern Macros

Keynote by Robby Findler



Modern Macros

Racket’s approach to macros is the latest point in an evolution that started in 1963 with Lisp’s macros. Building on those ideas, Racket’s macros have evolved so far that, to a modern macro programmer, macros are more helpfully understood as extending and manipulating the compiler’s front end than as a mechanism for textual substitution or syntactic abstraction.

Having a malleable compiler front end naturally enables succinct implementations of many domain-specific and embedded languages. A look at the Racket ecosystem reveals a wealth of examples. Scribble, a language for writing texts uses a LaTeX-inspired syntax and has been used to write thousands of pages of documentation, dozens of research papers, and at least two books. Redex, a language for writing and testing operational semantics, has helped numerous researchers debug their semantics and explore their ideas. Racket’s sister-language, Typed Racket, boasts numerous type-level innovations and full-fledged interoperability with untyped code. Beside these large efforts, Racket’s macros also have enabled extensions on the medium scale as well, being the basis for its pattern matcher, class system, contract system, family of for loops, and more. On the small scale, project-specific macros are common in Racket codebases, as Racket programmers can lift the language of discourse from general programming-language constructs to project-specific concerns, aiding program comprehension and shrinking codebase size.

In this talk, I’ll discuss the essential aspects of Racket’s macro system design, showing how they enable language-oriented programming and provide an intellectual foundation for understanding modern macros. These aspects all center on the idea of automatically managing scope and taking advantage of its automatic management.

Going beyond implementing languages, the data structures supporting automatic scope management have proven central to DrRacket (the Racket IDE), specifically its rename refactoring and its ability to navigate code-bases via uses and definitions of identifiers. Recently, Racketeers have begun to explore how more aspects of Racket’s macro system can support sophisticated IDE tooling for programming languages in the Racket ecosystem. I will try to paint a picture of where we hope to go with that work as well.

source code repo for the talk GitHub - rfindler/modern-macros-talk


If anyone is interested in the papers referenced at the beginning of the talk:

Eugene Kohlbecker, Daniel P. Friedman, Matthias Felleisen, and Bruce Duba. 1986. Hygienic macro expansion. In Proceedings of the 1986 ACM conference on LISP and functional programming (LFP '86). Association for Computing Machinery, New York, NY, USA, 151–161. https://doi.org/10.1145/319838.319859

William Clinger and Jonathan Rees. 1991. Macros that work. In Proceedings of the 18th ACM SIGPLAN-SIGACT symposium on Principles of programming languages (POPL '91). Association for Computing Machinery, New York, NY, USA, 155–162. https://doi.org/10.1145/99583.99607

R. Kent Dybvig, Robert Hieb, and Carl Bruggeman. 1992. Syntactic abstraction in Scheme. Lisp Symb. Comput. 5, 4 (Dec. 1992), 295–326. https://doi.org/10.1007/BF01806308

Matthew Flatt. 2002. Composable and compilable macros: you want it when? In Proceedings of the seventh ACM SIGPLAN international conference on Functional programming (ICFP '02). Association for Computing Machinery, New York, NY, USA, 72–83. https://doi.org/10.1145/581478.581486

Matthew Flatt. 2002. Composable and compilable macros: you want it when? SIGPLAN Not. 37, 9 (September 2002), 72–83. https://doi.org/10.1145/583852.581486

Matthew Flatt. 2016. Binding as sets of scopes. SIGPLAN Not. 51, 1 (January 2016), 705–717. https://doi.org/10.1145/2914770.2837620

Matthew Flatt. 2016. Binding as sets of scopes. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '16). Association for Computing Machinery, New York, NY, USA, 705–717. https://doi.org/10.1145/2837614.2837620

May also be of interest:

William D. Clinger and Mitchell Wand. 2020. Hygienic macro technology. Proc. ACM Program. Lang. 4, HOPL, Article 80 (June 2020), 110 pages. https://doi.org/10.1145/3386330

And video: PLDI 2021: Hygienic Macro Technology

1 Like

Thanks for posting this! Nicely done. That audience was right on the borderline between inquisitive and irritating... I'm thinking I may show this in class tomorrow.

1 Like

It would be interesting to hear how your students respond.

I couldn’t really hear the questions, which was a shame. I’m hoping I’ll have better luck with headphones or maybe the questions were captured in the transcript.


Thanks for posting this and finding the citations and DOIs. I've added that to the README.md in the source code repo for the talk.


Was the talk recorded by any chance?



Best regards

Stephen :beetle:

1 Like

Oh! Super happy to hear about the source code for the slides, I will 100% use this (with credit) the next time I present macros.

1 Like

Someone on lobster.rs reminded me that @robby mentioned a paper - did they get the right paper?

Around 22:06 he mentions “sometimes you want to be able to temporarily change what the IR is”, and that there’s a nice paper about it. It must be this: Macros for Domain-Specific Languages.

1 Like

I suppose that's the one and also https://docs.racket-lang.org/ee-lib/index.html


Sounds like the talk was building up to mentioning Resyntax-related tooling at the very end there :eyes:

1 Like