# Alternative Syntax for multiline Macros?

**URL:** <https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [October 6, 2017, 11:30am UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290 "2017-10-06T11:30:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sighoya](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@Sighoya](https://discourse.julialang.org/u/Sighoya)\
**Post date:** [October 6, 2017, 11:30am UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/1 "2017-10-06T11:30:07Z")

</div>

Is it possible to change the semantics for multiline macros, such that:

```julia
@some_macro begin
...
end

```

can be formulated to

```julia
@some_macro
begin 
...
end

```

where some\_macro is some multiline macro. The latter syntax is better for code formatting and is more natural in my eyes.  
Maybe this is not possible, an alternative would be:

```julia
@@some_macro
begin 
...
end

```

to state that some\_macro should be used in multiline mode with @@.

What do you think about?

---

<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:** [October 6, 2017, 11:54am UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/2 "2017-10-06T11:54:08Z")

</div>

What’s the problem with having the macro and `begin` on the same line? Your editor should take care of code formatting, and perhaps highlighting will help your eyes get used to it.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [October 8, 2017, 2:51am UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/3 "2017-10-08T02:51:46Z")

</div>

then we should add an FAQ for distinguishing macro from python’s decorators 🙃

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [October 8, 2017, 10:11am UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/4 "2017-10-08T10:11:26Z")

</div>

I must say I have often wished that multiline macro can be supported more directly, i.e. without the `begin`, to be able to make new syntax constructs which feel a bit less second class. I also thought about the `@@some_macro` syntax:

```julia
@@C_for i=0 i<10 i+=2
    dostuff()
end
```

---

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [October 17, 2017, 4:06pm UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/5 "2017-10-17T16:06:11Z")

</div>

I like this idea, it somehow feels wrong to put a macro in front of a type declaration to me. It feels like I’m messing up the more official syntax with a less official syntax. Or maybe its just that it pushes something I expect to see at the start of a line into the middle of a line, so it’s harder to scan the code. Consider

```julia
@auto_hash_equals struct A
  a::Int
end

```

vs

```julia
@@auto_hash_equals
struct A
  a::Int
end

```

---

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [October 17, 2017, 4:08pm UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/6 "2017-10-17T16:08:36Z")

</div>

How would you feel about

```julia
@@C
for i=0 i<10 i+=2
    dostuff()
end

```

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [October 17, 2017, 4:23pm UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/7 "2017-10-17T16:23:10Z")

</div>

It doesn’t seem to improve much upon the status quo `@C for i=... end`, besides allowing to put `for` on a separate line. My wish would be to have `@@macroname ...end` without having to introduce a `begin end` block (with `@@C_for` this can be split into `@@C for` as you did because `for` is a julia block introducer, but this doesn’t work in the general case).

---

<div class="post-metadata">

**Author:** ![musm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/musm/32/3675_2.png) [@musm](https://discourse.julialang.org/u/musm)\
**Post date:** [October 30, 2017, 8:59pm UTC](https://discourse.julialang.org/t/alternative-syntax-for-multiline-macros/6290/8 "2017-10-30T20:59:35Z")

</div>

see  
[https://github.com/JuliaLang/julia/issues/18612](https://github.com/JuliaLang/julia/issues/18612)
