01
Macros and Metaprogramming
Pattern-based code generation being a slice of the language rather than a template, generation in attribute and derive form moving into a separate compilation step, and generated syntax being used to build a readable interface.
- 01 Declarative Macros The course's measurement core runs from inside the program and places twelve observations into four classes — still holds, handed to the writer, outside the language, nobody checks it; the distribution is 4/3/2/3, and this lesson deepens only the two observations that fall into the 'still holds' class: the body a macro generates passes type checking, and a name inside the macro does not clash with the caller's.
- 02 Procedural Macros A program calls the compiler twice with std::process::Command — first a procedural macro crate, then the source that uses it — and prints only the compiled/not-compiled classification and the output match; the generated body again falls into the still holds class, but this time generation happens not in the same file but in a separate compilation step.
- 03 Domain-Specific Languages The same routing structure is built separately with a macro-written version and a hand-written version, shown by running it to produce the same result, and the macro version is measured for how many lines it shortens the source by; but a macro's output being readable does not bring correctness — a logically wrong path-function binding passes type checking just as easily.