I am trying to write a macro which would transform
@enum_and_dict(foo, foodict, "A" => A, "B" => B)
@enum foo A B foodict = Dict("A" => A, "B" => B)
I have tried this:
macro enum_and_dict(enumname, dictvar, pairs...) function expr_second(expr) @assert expr.head ≡ :(=>) "$expr is not a Pair." esc(expr.args) end quote @enum($(esc(enumname)), $(map(expr_second, pairs)...)) $(esc(dictvar)) = Dict($(pairs...)) end end
Dict part works fine, but for the first one I get a very complicated expression, and I don’t know why, or how to fix it.