## Problem:

  * A second invocation causes error because of **{.inject.}**


    
    
    INim 0.6.1
    Nim Compiler Version 2.0.4 [MacOSX: amd64] at 
/Users/dennismisener/.nimble/bin/nim
    nim> template tapIt*[T](obj: T, code: untyped): T =
      block:
         let it {.inject.} = obj
         code
         it
    
    nim> var num = 123
    nim> echo num.tapIt(echo 2 * it)
    246
    123
    nim> echo num.tapIt(echo 2 * it)
    Error: redefinition of 'it'; previous declaration here: 
/private/var/folders/dn/zz9c2pmx3qddx39kj0btzx340000gn/T/inim_1714005760.nim(9, 
9)
    
    
    Run

What about :
    
    
    INim 0.6.1
    Nim Compiler Version 2.0.4 [MacOSX: amd64] at 
/Users/dennismisener/.nimble/bin/nim
    nim> template tapIt*[T](obj: T, code: untyped): T =
    ....     let it {.inject.} = obj
    ....     code
    ....     it
    ....
    nim> var num = 123
    nim> echo num.tapIt(echo 2 * it)
    246
    123
    nim> echo num.tapIt(echo 2 * it)
    246
    123
    
    
    Run

Reply via email to