MacroTools
is already good to use, but some might not like its notation of capturing via underlines(struct a_ ... end
). In this regarding pattern matching may help.
Last time I looked it was not so easy to figure out how to use them
If you feel this way it shows that pattern matching is not that successful, because the point of pattern matching is you should be able to use it, understand it without learning about it.
I’m not sure if you’ve ever used Expr
or things like :(a + $b)
to build expressions, but if so, you should be able to use and understand libraries like MLStyle because deconstructions are almost same as constructions.
a = :(f(1))
b = :(g(1))
@match :($a + $b) begin
:($c + $d) =>
At here, you deconstruct things like how they’re constructed, so what makes you think it’s not easy? I think your answer could unveil a frequent question that I didn’t realized these years. Thanks in advance.
I ran into issues with capital letters being special (I forget in which package)
It may be MLStyle, and it’s a routine to use capitalized identifiers for constructors/deconstructors.
Is it easy to make a faster drop-in replacement for
MacroTools.@capture
?
This depends on what you expect. We’d say using pattern matching is more extensible and customizable, but MacroTools is already a successful encapsulation so using MacroTools might be better. If you want, you can check
this 2 implementation of capture
: https://thautwarm.github.io/MLStyle.jl/latest/tutorials/capture/ ,
but the notations are slightly different.