In the context of program generation, multistage programming (MSP, staging for short) as established by Taha and Sheard [2] allows programmers to explicitly delay evaluation of a program expression to a later stage (thus, staging an expression). The present stage effectively acts as a code generator that composes (and possibly executes) the program of the next stage.
However, Taha and Sheard write (emphasis mine):
A multi-stage program is one that involves the generation, compilation, and execution of code, all inside the same process. Multi-stage languages express multi-stage programs. Staging, and consequently multi-stage programming, address the need for general purpose solutions which do not pay run-time interpretive overheads.
They than go on to several references to older work allegedly showing that staging is effective, which suggests that the concept is even older. They don’t give a reference for the term itself. These statements seem to be orthogonal, if not contradictory; maybe what Rompf and Odersky write is an application of what Taha and Sheard propose, but maybe it is another perspective on the same thing. They seem to agree that an important point is that programs (re)write parts of themselves at runtime, but I do not know whether that is a necessary and/or sufficient ability. So, what is staging respectively are interpretations of staging in this context? Where does the term come from?
- Lightweight Modular Staging: A Pragmatic Approach to Runtime Code Generation and Compiled DSLs by T. Rompf and M. Odersky (2012)
- MetaML and multi-stageprogramming with explicit annotations by W. Taha and T. Sheard (2000)
Asked By : Raphael
Answered By : Uday Reddy
- How to define staged functions?
- What programming languages and type systems should be used for defining staged functions?
- What is the semantics of such languages?
- How do we ensure the coherence and correctness of staged functions?
- What techniques are useful for automatically or semi-automatically constructing staged functions?
- How do we prove the correctness of such techniques?
Staged computation can be very important in practice. In fact, every compiler is in effect a staged computation. Given a source program, it constructs a translated and optimized target program, which can then take the actual input and calculate the result. It is hard to write staged computation programs in practice because we have to juggle the multiple stages and make sure that the right things are done at the right time. Everybody who has written a compiler has struggled with such issues. It is also hard to write programs that write other programs, may they be machine language programs (compilers), SQL queries (database manipulations) or HTML/Server Pages/Javascript code (web applications) and myriads of other applications. The researchers in staged computation aim to create good languages and tools that make it easier and safer to create such applications.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/2869