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()
I don’t see any hygiene issues with @sourceshow