JuliaLang/julia — pull request #7474 by Keno (2014-06-30 18:51:40+00:00)
Title: WIP: Staged functions

This is my work in progress for staged functions (#7311). It almost works, but there's a few things left to discuss.

- [ ] Syntax: @StefanKarpinski hates `stagedfunction foo(); end`. @JeffBezanson proposed `staged foo(); end`, though there's the question if we want to reserve that keyword

- [ ] Caching. E.g. consider the following:

```
julia> stagedfunction foo(a,b)
println(a,b)
:(a+b)
end

julia> foo(1,2)
Int64Int64
3

julia> foo(1,2)
3

julia> bar() = foo(1,2)
bar (generic function with 1 method)

julia> bar()
Int64Int64
Int64Int64
3

julia> bar()
3

julia> baz() = foo(1,2)
baz (generic function with 1 method)

julia> baz()
Int64Int64
Int64Int64
3
```
Hopefully calling the staged function that many times can be avoided. In any case, this point isn't critical.

- [ ] Staged functions throwing errors. I'm not handling this yet. In the runtime case this mostly works already, but for type inference we need to intercept and return Any/NF.

Thanks to @timholy and @jakebolewski for hacking on this with me on Saturday.