# Retrieve unevaluated symbol inside \`@eval\`

**URL:** https://discourse.julialang.org/t/retrieve-unevaluated-symbol-inside-eval/118978
**Category:** General Usage
**Tags:** metaprogramming, eval
**Created:** [September 3, 2024, 8:58am UTC](https://discourse.julialang.org/t/retrieve-unevaluated-symbol-inside-eval/118978 "2024-09-03T08:58:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [September 3, 2024, 8:58am UTC](https://discourse.julialang.org/t/retrieve-unevaluated-symbol-inside-eval/118978/1 "2024-09-03T08:58:57Z")

</div>

In one of my packages I use `@eval` to define a list of functions in a loop based on symbols. I would also like to use the symbol without evaluating it, but I can’t figure out how. Maybe it’s an XY problem?

```julia
julia> for s in [:a, :b, :c]
           f = Symbol("f_", s)
           # I want f_a(:a) = true and f_a(any_other_symbol) = false
           @eval $f(x::Symbol) = x == $(Symbol(repr(s)))
       end

julia> f_a(:a)
ERROR: UndefVarError: `:a` not defined

```

---

<div class="post-metadata">

### Author: ![kdpsingh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdpsingh/32/215018_2.png) [@kdpsingh](https://discourse.julialang.org/u/kdpsingh)
#### Post date: [September 3, 2024, 9:23am UTC](https://discourse.julialang.org/t/retrieve-unevaluated-symbol-inside-eval/118978/2 "2024-09-03T09:23:56Z")

</div>

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:

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

```
