3 ms·
Nice article, although I couldn't really understand some of the examples which had template in it.
by StrykerKKD 12y ago
Nice article, although I couldn't really understand some of the examples which had template in it.
- RaecKK 12y agoAgreed. When the manual says you can pattern match with term rewriting macros, I think of Erlang pattern matching. Would something like this be possible? template mysum{a = @[]}(a: seq[int]): int = 0 template mysum{a}(a: seq[int]): int = while a.low <= a.high: a[a.low] + mysum(a[a.low + 1 .. a.high]) var x: seq[int] = @[1, 2, 3] echo mysum(x)
- def- 12y agoTerm rewriting templates are only supposed to be optimizations, not change the semantics. They happen on the AST, so the pattern matches are on the AST as well. You won't get the actual values of any variables, they aren't even known at compile-time anyway.