Alternative Syntax for multiline Macros?

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

@some_macro begin
...
end

can be formulated to

@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:

@@some_macro
begin 
...
end

to state that some_macro should be used in multiline mode with @@.

What do you think about?

1 Like

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.

3 Likes

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

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:

@@C_for i=0 i<10 i+=2
    dostuff()
end
3 Likes

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

@auto_hash_equals struct A
  a::Int
end

vs

@@auto_hash_equals
struct A
  a::Int
end
1 Like

How would you feel about

@@C
for i=0 i<10 i+=2
    dostuff()
end
1 Like

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).

1 Like

see
https://github.com/JuliaLang/julia/issues/18612