I suddenly had a “metaphysical” doubt when learning about the
I imagined that such macro could be used to completly evaluate a given expression and replace it by its result at compile time. It cannot.
Then I though that maybe
@eval would do that. But trying
julia> a=1 julia> f() = a julia> g() = @eval f() julia> a=2 julia> g() 2
one can see that it wont do.
Finally, I got a way to do it through some macro like:
macro capture(expr); eval(expr); end
julia> a=1 julia> f() = a julia> g() = @capture f() julia> a=2 julia> g() 1
Now, I’m wondering:
Is there any uses cases for this functionality?
If yes, is there some similar macro in Base?
If not, is there another, more common, way to have this behavior?