I’m pretty sure there is no way, and I’m also pretty sure that this is by design. In order to be able to compile functions, some restrictions need to be imposed on local scopes, such as no eval into the local scope of the function. I think this falls into the same category. Just just a dict.
The problem is that eval always executes in global scope (or a module), I am not sure if the following helps you:
macro p(s)
@assert s.head == Symbol("=")
y = string(s.args[1])
_y = s.args[1]
x = s.args[2].value
quote
$(esc(_y)) = $(esc(x))
println($y, " is equal to ", $(esc(x)))
end
end
function f()
x = 2
@p y = :x
y
end
f()