Racket glossary

TIL 'Staged metaprogramming'

Is this a good one to add to the Racket Glossary?

I think [PADL’23] Modern Macros provides more details, but doesn't use the term.

“Staged programming” refers to compilation models that allow a program to generate code that is then run at compile-time to produce a second program, after which the first program can be discarded. There are a few different approaches to providing language support for this.

Obviously, the simplest way is to just write a program that just writes another program to stdout. But this is pretty unpleasant in practice. Staged metaprogramming systems provide structured ways to do this that are integrated into the language and compiler.

The main approaches are Lisp-style macro systems, which allow arbitrary transformations on syntax trees to be executed at compile-time, and MetaML-style staged programming systems, which allow compile-time functions to generate expressions that are spliced into the program.

Staged metaprogramming allows you to write embedded DSLs that are effectively an extension of the host language’s compiler, so there is no need to do any processing on the embedded language’s syntax at runtime. In a sense, it is more tagless and more final than tagless final.

Source: @lexi.lambda https://twitter.com/lexi_lambda/status/1645889624617672704?s=20

2 Likes