On term rewriting macros

2023-06-29 Thread hamidrb80
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

On term rewriting macros

2021-04-22 Thread Araq
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.

On term rewriting macros

2021-04-22 Thread haxscramper_
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

On term rewriting macros

2021-04-22 Thread Araq
> 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

On term rewriting macros

2021-04-22 Thread timothee
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

On term rewriting macros

2021-04-22 Thread Araq
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