Could you summarise briefly what this is for?
A brief summary is, we hope MacroTools.jl could use MLStyle.jl to achieve such a
AYC, currently, MacroTools.jl’s
@capture uses underscore to denote the variables to be capture, e.g.,
struct typename_ fields__ end, which is quite an inconsistent notation that makes many people including me feel uncomfortable. Although there is a background about why don’t use
it’s not that correct for capturing
$ expression is also very rare, so you can transform Expr(:&, arg) into something else and then perform capturing if necessary.
The main advantages of
$ notation instead of underscore are
Straightforward. In the issue referred above, people think so. Julia might be the only one who’s homoiconic except Lisp idioms, which is the root reason why Julia macros work. We should follow how ASTs are inserted(
:($a + b) ), and use this notation as how ASTs are “uninserted”/captured.
You can introduce other pattern matching into @capture, like type matching
struct $(typename :: Symbol) ..., packing
[1, 2, $(a...), last] and so on.
Do you have applications in mind for which the speed of
@capture from MacroTools is a bottleneck?
Usually, we don’t care about performance of the tasks that MacroTools.jl is for. Macros are often used for codegen or staging computations, and even if your macro processing is very slow, only the first time you load a module would be affected.
However, still some scenario can be performance sensitive. Some people who prefer DSLs(domain specific languages) might use MacroTools to rewrite almost all part of the ASTs, which causes that a tiny modification on a DSL would produce totally new ASTs. In this case, MacroTools would be regarded as something like a parser, which is performance significant.