How to create a macro for creating a symbol in Julia -
i trying create string literal macro in julia create symbol
, s"x"
same :x
. not work:
julia> macro s_str(p) symbol(p) end julia> s'x' error: s not defined julia> s"x" error: x not defined
the reason macro hygiene. can either
macro s_str(p) quote symbol($p) end end
which easy read, or more complicated equivalent.
macro s_str(p) esc(:(symbol($p))) end
macros julia-lang julia-macros
No comments:
Post a Comment