This simple definition does not work: @formula2(y~x) does not give the same output as @formula(y~x). How could I define @formula2 to obtain exactly the same output as @formula?
julia> for i in 1:3
@m2 i
end
ERROR: UndefVarError: i not defined
Stacktrace:
[1] macro expansion at ./REPL[10]:2 [inlined]
[2] top-level scope at ./<missing>:0
With my usual apology to resurrecting a dormant thread, this thread came up high in a google search and I wanted to link it to the more relevant thread:
In short, I wanted to call @show within a macro, and the seemingly correct macro requires an esc around the whole returned expression:
macro sourceshow(expr)
si = Base.CoreLogging.@_sourceinfo
fileline = "$(si[2]):$(si[3])"
esc(:(begin
println($fileline)
@show($expr)
end
))
end
function f()
y = 4
@sourceshow y
end
@show macroexpand(Main, :(@sourceshow y))
f()
macro sourceshow(expr)
si = Base.CoreLogging.@_sourceinfo
fileline = "$(si[2]):$(si[3])"
esc(:(begin
println($fileline)
@show($expr)
end
))
end
function f()
y = 4
@sourceshow y
end
@show macroexpand(Main, :(@sourceshow y))
f()