Multi-Stage Programming with Splice Variables: Safe and Predictable Code Generation

2025-06-28

This paper introduces a novel technique called Multi-Stage Programming (MSP) that allows programs to generate other programs. To ensure safe and predictable code generation, the authors introduce the concept of "splice variables." Splice variables provide fine-grained control over the code generation process and seamlessly scale to advanced features like code pattern matching and rewriting. The type system automatically tracks variable dependencies, ensuring that the generated code is always well-formed, properly scoped, and type-checks correctly. The paper demonstrates the power of splice variables with examples such as generating a power function and showcases features like code pattern matching and rewriting.

Read more