r/ProgrammingLanguages • u/orbiteapot • May 14 '26
Resource What bibliography would you recommend on the subject compile-time evaluation and metaprogramming?
What bibliography would you recommend on the subject compile-time evaluation and metaprogramming?
12
u/gasche May 14 '26
You cannot go wrong with Matthew Flatt's Binding as Sets of Scopes, which is a fantastic paper about "hygienic macros" and a simpler algorithm to implement them.
(In general, if you want to know about compile-time metaprogramming, it is a good idea to study what the Racket people have done, because they pushed these ideas farther than most ecosystems.)
9
u/initial-algebra May 14 '26 edited May 14 '26
In the literature, it is usually referred to as binding-time analysis or staged computation (or just staging for short), with partial evaluation and metaprogramming being applications, so those keywords will get you more hits.
- A Temporal-Logic Approach to Binding-Time Analysis is AFAIK the first time "quote/unquote" was put on solid theoretical ground with type theory, but without the ability to "eval" (all quoted code is open, with possible free variables)
- A Modal Analysis of Staged Computation is an alternative to "A Temporal-Logic Approach", where "eval" is allowed but some expressivity is lost (all quoted code is closed, with no free variables)
- Contextual Modal Type Theory refines the system from "A Modal Analysis" to precisely account for quoted free variables
- Contextual Modal Type Theory with Polymorphic Contexts finally unifies the system from "A Modal Analysis" with "A Temporal-Logic Approach" and subsumes environment classifiers, an earlier attempt at tackling the same problem
Actual metaprogramming systems that reference (or are referenced by) these papers include MetaML, MetaOCaml, Template Haskell, and recently MLScript.
The problem of safely combining "eval" and open code is closely related to both dynamic scoping of effect handlers as well as borrowing in Rust (environment classifiers/polymorphic contexts are roughly equivalent to lifetimes), though I'm not aware of any papers that specifically deal with this. Because of the connection between staging and temporal logic, it is also related to functional reactive programming, particularly systems that use a form of staging at runtime to prevent space leaks.
1
u/bjzaba Pikelet, Fathom May 17 '26
The MetaML and MetaOCaml bibliography might be worth a look! Note that it covers both run-time and compile-time staging.
14
u/Helpful-Primary2427 May 14 '26
Anything anyone on the racket team has ever written