# Why can't I generate a function with multiple arguments using Symbol("arg1,arg2")?

**URL:** <https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 25, 2020, 11:10am UTC](https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254 "2020-09-25T11:10:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 25, 2020, 11:10am UTC](https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254/1 "2020-09-25T11:10:37Z")

</div>

I’m not sure what’s going on here, and I’m not sure if this is a valid use of `Symbol`s either.

```julia
julia> for TA in [Symbol("a,b")]
       @eval f($TA) = a + b
       end

julia> methods(f)
# 1 method for generic function "f":
[1] f(a,b) in Main at REPL[1]:2

julia> f(1,2)
ERROR: MethodError: no method matching f(::Int64, ::Int64)
Closest candidates are:
  f(::Any) at REPL[1]:2
Stacktrace:
 [1] top-level scope at REPL[3]:1

julia> f(1)
ERROR: UndefVarError: a not defined
Stacktrace:
 [1] f(::Int64) at ./REPL[1]:2
 [2] top-level scope at REPL[4]:1

```

What exactly is being generated here?

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 25, 2020, 11:22am UTC](https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254/2 "2020-09-25T11:22:54Z")

</div>

Macro interpolation doesn’t work the same as string interpolation. I.e. this is _not_ what you’re getting in that eval

```julia
julia> TA = Symbol("a,b");

julia> "f($TA)"
"f(a,b)" # you're not getting this. At least not the way you think...

```

You’re getting something more like

```julia
f(Symbol("a, b")) = a + b

```

So it’s a one argument function, with input argument `Symbol("a, b")`. What’s incredibly bizarre about that input argument name, is that it prints as though a and b are different things! That’s what’s throwing you off:

```julia
julia> methods(f)
# 1 method for generic function "f":
[1] f(a,b) in Main at REPL[5]:1

julia> f(1,1)
ERROR: MethodError: no method matching f(::Int64, ::Int64)
Closest candidates are:
  f(::Any) at REPL[5]:1
#...
julia> f(1)
ERROR: UndefVarError: a not defined
#...

```

Note that in the first case, there is no such function at all. The method printout is just messed up because your symbol is really strange. In the second case, there _is_ such a function (one argument) but it doesn’t know what to do with `a` and `b`, since they are _not_ the inputs.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [September 25, 2020, 11:39am UTC](https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254/3 "2020-09-25T11:39:50Z")

</div>

You probably want something like this instead:

```julia
julia> for TA in [[:a, :b]]
           @eval f($(TA...)) = a + b
       end

```

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 25, 2020, 11:43am UTC](https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254/4 "2020-09-25T11:43:08Z")

</div>

Thanks, this was quite insightful!

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [September 25, 2020, 11:46am UTC](https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254/5 "2020-09-25T11:46:42Z")

</div>

This also seems to be a printing bug, `Symbol("a,b")` in method signatures should be displayed as `var"a,b"`. Would you mind opening an issue?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 25, 2020, 12:05pm UTC](https://discourse.julialang.org/t/why-cant-i-generate-a-function-with-multiple-arguments-using-symbol-arg1-arg2/47254/6 "2020-09-25T12:05:53Z")

</div>

Filed an [issue](https://github.com/JuliaLang/julia/issues/37743)
