# New syntax for multi-line macrocalls

**URL:** <https://discourse.julialang.org/t/new-syntax-for-multi-line-macrocalls/21571>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [March 7, 2019, 1:45pm UTC](https://discourse.julialang.org/t/new-syntax-for-multi-line-macrocalls/21571 "2019-03-07T13:45:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evey/32/214967_2.png) [@Evey](https://discourse.julialang.org/u/Evey)\
**Post date:** [March 7, 2019, 1:45pm UTC](https://discourse.julialang.org/t/new-syntax-for-multi-line-macrocalls/21571/1 "2019-03-07T13:45:18Z")

</div>

Hi! 😄 This is a proposal for an additional macrocall syntax which will parse past newlines until an `end` is encountered. The idea is to have a syntax which allows using a macro more akin to reserved keyword blocks such as `function`, `struct`, etc., without requiring manual use of `begin ... end`. The syntax proposed here uses `@@` because this is currently a syntax error, but better alternatives may exist.

As an example, suppose I want to save three characters when defining functions, so I define the macro:

```julia
macro fun(signature, lines...)
    quote
        function $(signature.args[1])($(signature.args[2:end]...))
            $(lines...)
        end
    end |> esc
end

```

Then with the new syntax rule, the following would be a valid macrocall:

```julia
@@fun f(x)
    y = x^2
    return y
end

```

and equivalent to

```julia
@fun f(x) y = x^2 return y

```

A more useful example might be something like:

```julia
macro loop(before, condition, body, after)
    quote
        $before
        while $condition
            $body
        end
        $after
    end |> esc
end

```

resulting in the following macrocall:

```julia
@@loop
    begin
        x = 1
        y = 10
    end
    x < y
    x += 1
    println(x)
end

```

being equivalent to:

```julia
@loop begin
    x = 1
    y = 10
end begin
    x < y
end begin
    x += 1
end begin
    println(x)
end

```

Of course, these are simplified examples to illustrate the main idea, and actual macros which make use of this syntax would presumably add a lot of boilerplate around the transformed expressions.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 7, 2019, 2:01pm UTC](https://discourse.julialang.org/t/new-syntax-for-multi-line-macrocalls/21571/2 "2019-03-07T14:01:09Z")

</div>

IIRC @jeff.bezanson and I had discussed this very syntax idea at some point.

---

<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:** [March 7, 2019, 4:07pm UTC](https://discourse.julialang.org/t/new-syntax-for-multi-line-macrocalls/21571/3 "2019-03-07T16:07:25Z")

</div>

3 posts were split to a new topic: [Pattern matching for macros](https://discourse.julialang.org/t/pattern-matching-for-macros/21583)

---

<div class="post-metadata">

**Author:** ![Evey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evey/32/214967_2.png) [@Evey](https://discourse.julialang.org/u/Evey)\
**Post date:** [March 7, 2019, 2:59pm UTC](https://discourse.julialang.org/t/new-syntax-for-multi-line-macrocalls/21571/4 "2019-03-07T14:59:09Z")

</div>

Actually, I personally did not think of this suggestion as being related to pattern matching, but instead being all about the aesthetics; having a clean way to split arguments to a macro over several lines. That it shares some features with pattern matching is to me tangential. Having a “line continuation” character could achieve the same purpose, but I personally don’t know which character should be used for this and I am not super fond of how it reads (e.g., `\` in Python).

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [March 7, 2019, 8:33pm UTC](https://discourse.julialang.org/t/new-syntax-for-multi-line-macrocalls/21571/5 "2019-03-07T20:33:18Z")

</div>

Line continuation PR:

> <https://github.com/JuliaLang/julia/pull/29273>
>
> Closes #27533 by adding a line continuation character which is only valid in spa…ce sensitive parsing contexts (see https://github.com/JuliaLang/julia/issues/27533#issuecomment-422672161)
> 
> I've often wanted a nice way to continue space separated argument lists for macros across multiple lines. Resorting to function call syntax isn't very satisfying because it's quite syntactically different from the usual way that macros look in julia code.
> 
> Demo:
> 
> \`\`\`julia
> \# Valid - space sensitive context
> @info "A message which could be rather long" ⤸
> a="something more" ⤸
> b="another thing"
> 
> \# Invalid - there should only be one way to do this
> x = some\_variable ⤸
> + other\_variable
> \# Valid - the current, perfectly good convention for writing this
> x = some\_variable +
> other\_variable
> \`\`\`
