Pattern matching for macros

I know that I have brought this up a number of times in these forums, so I hope I’m not becoming annoying, but I can’t help but feel that this falls well short of addressing the real problem of lacking proper pattern matching for writing macros anywhere in Base or stdlib. (And I am assuming that this suggestion is more about pattern matching blocks than it is about omitting a begin.)

I realize that there are many suggestions on these forums about adding things to Base or the stdlib which are unwarranted because the suggested functionality is better off in a separate package, but I can’t help but feel that tools for writing easily understandable macro code are a special case, and the existence of this post indicates that others feel the same.

In multiple cases I have found myself in a position of making contributions to packages which contain baffling macro code that is extremely difficult to maintain. It’s not because the authors were bad at writing macro code, it’s rather because with Julia’s complicated AST metaprogramming is simply extremely ugly without special tools, and the authors were either unaware of MacroTools or were nervous about its maintenance (I was explicitly told this by the package authors in at least one case).

I personally would be perfectly happy to continue using MacroTools itself for my own projects, but it seems likely to me that much of the communtiy will remain either unaware of it, or will continue to be unwilling to use it, or perhaps feel motivated to create unnecessary forks. I feel that the proliferation of bewildering, difficult to maintain macro code is very bad for the Julia ecosystem, and I would love if something could be done to “stem the tide” before such code becomes even more prevalant. As you can see from the MacroTools package, pattern matching for metaprogramming doesn’t have to consist of much code itself, but it can save thousands and thousands of lines of confusing, macro code that contributers are afraid to touch.


Sorry, I did not mean to try to derail the thread. It seems to me that if you had good pattern matching on blocks, it would obviate the need for a special macro syntax on blocks, which was why I brought it up.

I think it’s a good suggestion, but I would strongly prefer having good pattern matching available to case-by-case special syntax.

No worries! I think good pattern matching is important too, but I see no reason why this suggestion (which is a change to the parser) would in any way negatively influence the adoption of MacroTools or a similar package. :wink:

However, MLStyle.jl just made an advancement.
Just make AST manipulations maintainable.


Simplify macro rewriters and avoid some prospective bugs by thautwarm · Pull Request #238 · queryverse/Query.jl · GitHub ,
Query.jl/table_query_macros.jl at 12a1d3c214f42bb63bd18aaa936f127798d74f46 · queryverse/Query.jl · GitHub