# Multi-stage programming

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Multi-stage_programming
> Markdown URL: https://mediated.wiki/source/Multi-stage_programming.md
> Source: https://en.wikipedia.org/wiki/Multi-stage_programming
> Source revision: 1330545412
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

'''Multi-stage programming''' ('''MSP''') is a variety of [metaprogramming](/source/metaprogramming) in which compilation is divided into a series of intermediate phases, allowing [typesafe](/source/type_safety) [run-time code generation](/source/Self-modifying_code).<ref>{{cite encyclopedia
|last=Taha
|first=Walid
|title=A gentle introduction to multi-stage programming
|encyclopedia=Domain-Specific Program Generation
|publisher=Springer
|year=2004
|pages=30–50
|url=http://www.cs.rice.edu/~taha/publications/journal/dspg04a.pdf
|archive-url=https://web.archive.org/web/20170804032218/http://www.cs.rice.edu/~taha/publications/journal/dspg04a.pdf
|archive-date=August 4, 2017
|url-status=dead
}}</ref>
Statically defined types are used to verify that dynamically constructed types are valid and do not violate the type system.

In MSP languages, expressions are qualified by notation that specifies the phase at which they are to be evaluated. By allowing the specialization of a program at run-time, MSP can optimize the performance of programs: it can be considered as a form of [partial evaluation](/source/partial_evaluation) that performs computations at compile-time as a trade-off to increase the speed of run-time processing.<ref name="tcs00">{{cite journal
|last1=Taha
|first1=Walid
|last2=Sheard
|first2=Tim
|title=MetaML and multi-stage programming with explicit annotations
|journal=Theoretical Computer Science
|volume=248
|number=1
|year=2000
|pages=211–242
|url=http://www.cs.rice.edu/~taha/publications/journal/tcs00.pdf
|doi=10.1016/s0304-3975(00)00053-0
|doi-access=free
}}</ref>

Multi-stage programming languages support constructs similar to the [Lisp](/source/Lisp_(programming_language)) construct of quotation and <code>eval</code>, except that [scoping](/source/Scope_(computer_science)) rules are taken into account.<ref name="tcs00"/>

==References==
{{reflist}}

==External links==
* [https://web.archive.org/web/20130613174907/http://metaocaml.org/ MetaOCaml]

{{Programming paradigms navbox}}

Category:Programming paradigms
Category:Type systems

---
Adapted from the Wikipedia article [Multi-stage programming](https://en.wikipedia.org/wiki/Multi-stage_programming) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Multi-stage_programming?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
