Programming Languages · Cluster
Metaprogramming
Macros, reflection, and compile-time evaluation.
- 01 Token Substitution and Tree Substitution in Macro Expansion Why the C preprocessor rewrites flat token sequences while Lisp macros rewrite parsed forms, and how that choice changes precedence bugs, argument checking, and whether expansion is guaranteed to terminate.
- 02 Macro Hygiene and Identifier Capture How macro expansion causes identifiers to bind in the wrong scope, how gensyms and syntax objects prevent it, and what hygiene costs in equality checks and in generated names.
- 03 Quasiquotation, Unquotation, and Nesting Depth How quasiquote builds template structures with holes, why unquote must match the right quasiquote level, and how the level counter decides which parts of a nested template are evaluated.
- 04 Compile-Time Function Evaluation and Its Limits How a compiler runs ordinary functions during translation, why the interpreter inside the compiler must refuse some operations, and where the boundary between constant folding and program execution falls.
- 05 Runtime Reflection: Metadata Layout and Dispatch Cost What a class descriptor actually contains, why reflective invocation cannot be inlined, and how annotation lookup and dynamic proxies turn a static call into a table walk.
- 06 Procedural Macros and the Token Stream Contract What a procedural macro receives from the compiler, why the interface is a flat token sequence rather than a syntax tree, and what that costs in error reporting and incremental compilation.
- 07 Derive Macros and Structural Recursion Over Type Definitions How a derive macro walks a struct or enum field by field to generate implementations, what generic parameters and lifetimes force on the generated code, and why bound inference goes wrong.
- 08 Expansion Depth Limits and Token Opacity Why a recursive pattern-matching macro consumes one level of expansion depth per element it processes, how the recursion limit is raised, and why a captured fragment cannot be re-matched by a later pattern.
- 09 Phase Separation and the Ordering of Compilation Stages Why a macro must be defined before it is used, how phase levels propagate through module dependencies, and what transitive phase shifting costs in compilation work.
- 10 Multi-Stage Programming and Cross-Stage Persistence How staged languages type the distinction between code and its generation, what run and splice mean at each level, and why a value captured at one stage must be embeddable in the next.