the examples in the docs does no convenience me, why not use a template?
instead of
template optMul{`*`(a, 2)}(a: int): int = a+a
Run
just write:
template `*`(a: int, b: static[2]): int = a+a
Run
To make it clear: Enough people have tried to use "TR macros" for things other
than optimizations so a more general "rewrite system" would be acceptable too.
Then it cannot be disabled anymore but it's a price I'm willing to pay.
Another possible use case for term rewriting macros is user-defined warnings -
for example when converting from older API to a new one. Implicitly rewriting
everything is a bad idea, but making it easier to migrate old code, or prevent
accidental misuses is still useful. Paired with pattern matc
> the only question IMO is whether this would be more expensive (at CT) than
> current TRW, but I don't see why.
It looks equally expensive to me, that's not an improvement. ;-)
In my opinion the optimization needs an explicit _anchor_ point. Like so:
proc `*`(x, y: Matrix): Matrix
also:
* they hide infinite recursion bugs by truncating to a max depth
* the syntax is too foreign and not flexible enough (major point against)
the TRW general idea is useful though:
* optimization (eg: `ret &= a & b & c`)
* debugging + other use cases where you want to change behavio
Since it came up in the other thread, TR macros are not used (much) in the
standard library because they currently slow down compilations too much. They
are also hard to write, not because you end up with wrong optimizations (though
that's a possibility too), but because the optimizations are no