What I want to do is like this:
(let ((a (gensym)))
(eval
`(boundp ',a)))
and I want to construct something like
macro test()
var = gensym("var")
quote
isdefined($var) ? $var += 1 : $var = 0
@show $var
end
end
for i=1:10; @test; end
# Desired output:
# ##var#8589 => 0
# ##var#8589 => 1
# ...
But this is wrong, because the value of var is passed to isdefined, not the
symbol referring to it. So it's like having (eval `(boundp ,a)) in lisp. I
can do this instead:
macro test()
var = gensym("var")
eval(:($var = -1))
quote
$var += 1
@show $var
end
end
but this requires me to initialize the variable at the beginning.
What is the syntax for referring to the symbol stored in a variable, not
value of that symbol, inside a quoted expression?
Also, are there any guarantees about how long gensym's live in this case?
Does var go into global scope?
I'm only learning Julia, and I'm slightly confused by what it expects me to
write.