Hi,

I'm trying to add an `echo("OK")` to the end of a function. Here are the 
attempts. Could you please advise how to do this?

Thanks,
    Peter
    
    
    import macros
    
    # Illegal storage access. (Attempt to read from nil?)
    macro addEcho1(s: stmt): stmt =
      s.body.add(newCall("echo", newStrLitNode("OK")))
      result = s
    
    proc f1() {.addEcho1.} =
      let i = 1+2
      echo i
    
    # Internal error
    macro addEcho2(s: stmt): stmt =
      s.body.add(newCall(bindSym"echo", newStrLitNode("OK")))
      result = s
    
    proc f2() {.addEcho2.} =
      let i = 1+2
      echo i
    
    # Illegal storage access. (Attempt to read from nil?)
    macro addEcho3(s: stmt): stmt =
      s.body.add(parseExpr("echo \"OK\""))
      result = s
    
    proc f3() {.addEcho3.} =
      let i = 1+2
      echo i
    
    # internal error: expr(nkClosedSymChoice); unknown node kind
    macro addEcho4(s: stmt): stmt =
      s.body.add(newCall(bindsym"write",bindsym"stdout", newStrLitNode("OK\n")))
      result = s
    
    proc f4() {.addEcho4.} =
      let i = 1+2
      echo i
    
    # Illegal storage access. (Attempt to read from nil?)
    macro addEcho5(s: stmt): stmt =
      s.body.add(parseExpr("stdout.write \"OK\\n\" "))
      result = s
    
    proc f5() {.addEcho5.} =
      let i = 1+2
      echo i
    

Reply via email to