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 behavior globally with 
minimal code changes
  * it's a more principled way to handle things like dotOperators as I've 
argued here: 
<https://github.com/nim-lang/RFCs/issues/341#issuecomment-778572488>



instead how about introducing something that fits better with the language and 
is more flexible: 
    
    
    # instead of: template optMul{`*`(a, 2)}(a: int): int = a+a
    
    proc myCustomTRW(a: NimNode): NimNode {.rewrite.} =
      ## if returns nil, the expression is not rewritten, else it's rewritten
      if a.kind == nnkInfix and a[0].strVal == "*":
        result = genAst(lhs = a[1], rhs = a[2]): lhs + rhs
    
    
    Run

the semantics: each expression is matched (recursively) against each TRW in 
scope

the only question IMO is whether this would be more expensive (at CT) than 
current TRW, but I don't see why.

## links

  * 
<https://nim-lang.github.io/Nim/manual_experimental.html#term-rewriting-macros>


Reply via email to