# How to produce the code "f(a...,b...)"

**URL:** <https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950>\
**Category:** General Usage\
**Created:** [March 29, 2017, 2:03pm UTC](https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950 "2017-03-29T14:03:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [March 29, 2017, 2:03pm UTC](https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950/1 "2017-03-29T14:03:55Z")

</div>

I’m trying to generate the code `f(a...,b...)` from inside a macro. The following doesn’t seem to work because it adds an extra tuple around `a...` and `b...`,

```julia
julia> quote
           f($((:($i...) for i=[:a,:b])...))
       end
quote  
    f((a...,), (b...,))
end

```

Instead, I have to use an explicit `Expr` call,

```julia
julia> quote
           f($((Expr(:(...),i) for i=[:a,:b])...))
       end
quote 
    f(a..., b...)
end

```

Could any macro-guru’s help me out with a way to write this without resorting to using `Expr` (which I don’t like simply because I find it makes the code a bit harder to parse)? Thanks!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [March 29, 2017, 3:22pm UTC](https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950/2 "2017-03-29T15:22:29Z")

</div>

Just write a helper function that accepts as argument :a and returns the nasty code you don’t want to think about again.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [March 29, 2017, 5:04pm UTC](https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950/3 "2017-03-29T17:04:38Z")

</div>

Not sure I understand, sorry, can you elaborate? In any case, I was hoping no extra function was necessary, and it might just be a matter of getting the $'s and :'s in the right places in that first example, but maybe not…

---

<div class="post-metadata">

**Author:** ![fengyang.wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fengyang.wang/32/104_2.png) [@fengyang.wang](https://discourse.julialang.org/u/fengyang.wang)\
**Post date:** [March 29, 2017, 5:07pm UTC](https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950/4 "2017-03-29T17:07:01Z")

</div>

Are you sure you don’t have a stray comma somewhere? I can’t test this currently but I am surprised that the first block of code gives a tuple.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [March 29, 2017, 5:10pm UTC](https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950/5 "2017-03-29T17:10:05Z")

</div>

The parentheses aren’t actually part of the colon syntax. They’re required because : is earlier in the order of operations than … . Because they are “real” parentheses, they make a tuple, just like (a…) does. So the answer is no.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [March 29, 2017, 5:28pm UTC](https://discourse.julialang.org/t/how-to-produce-the-code-f-a-b/2950/6 "2017-03-29T17:28:10Z")

</div>

> [@bramtayl](#):
>
> The parentheses aren’t actually part of the colon syntax. They’re required because : is earlier in the order of operations than … . Because they are “real” parentheses, they make a tuple, just like (a…) does. So the answer is no.

Ah thanks yea that explanation totally helps get it right in my head what’s going on.

I suppose it would be nice if the first (if any) pairs of parenthesis after a “:” could _not_ be interpreted as a tuple, to allow you do `:($i...)` without making a tuple, but still give you the flexibility to make a tuple with `:(($i...))` if desired. Although I can easily imagine this having some unintended consequence I haven’t thought of…
