# Macro & tuple parsing

**URL:** <https://discourse.julialang.org/t/macro-tuple-parsing/9078>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [February 15, 2018, 11:04am UTC](https://discourse.julialang.org/t/macro-tuple-parsing/9078 "2018-02-15T11:04:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 15, 2018, 11:04am UTC](https://discourse.julialang.org/t/macro-tuple-parsing/9078/1 "2018-02-15T11:04:22Z")

</div>

I expect that this came up before, but I could not find an issue, so I am asking here. Consider

```julia
macro greedy(expr)
    esc(expr)
end

f(x, y) = x + y

```

then

```julia
julia> f(1, 2)
3

julia> f(@greedy 1, 2)
ERROR: MethodError: no method matching f(::Tuple{Int64,Int64})
Closest candidates are:
  f(::Any, ::Any) at REPL[34]:1

```

The issue is that

```julia
julia> parse("f(@greedy x, y)")
:(f(@greedy((x, y))))

```

so the macro takes the whole tuple as its argument.

This is a corner case of the use of `,` for function arguments and tuple element separators. I can see some logic behind it, and know that `f(@greedy(1), 2)` is a workaround, but parsing `"f(@greedy x, y)"` as `:(f(@greedy(x), y))` would occasionally feel more natural.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 15, 2018, 1:56pm UTC](https://discourse.julialang.org/t/macro-tuple-parsing/9078/2 "2018-02-15T13:56:46Z")

</div>

Imagine an expression like `@inbounds x, y = a[1]`: you really want `@inbounds` to apply to the whole destructured-tuple assignment, not just to `x`. That’s why the non-parenthesized form of macro application can’t be “greedy”.

The basic rule of thumb is that you should use `@greedy x y ...` only when you are applying a macro to a whole line (or a larger block), and use `@greedy(x,y)` otherwise.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 15, 2018, 2:08pm UTC](https://discourse.julialang.org/t/macro-tuple-parsing/9078/3 "2018-02-15T14:08:30Z")

</div>

I understand the rationale, but perhaps the documentation could clarify this.
