Retrieve unevaluated symbol inside `@eval`

This is because when you do $(Symbol(repr(s))), you are converting :a into the string ":a" (this is what repr() is doing), and when you convert it back to a symbol, it’s a symbol Symbol(":a") and not :a.

Here’s what you’re looking for:

for s in [:a, :b, :c]
    f = Symbol("f_", s)
    @eval $f(x::Symbol) = x == $(QuoteNode(s))
end
4 Likes