As far as I know you can't call a macro inside another macro. It doen't make 
sense anyway.

Use a compiletime proc. 
    
    
    import macros
    
    proc genVar(c: string): NimNode {.compiletime.} =
      # {.compiletime.} pragma is automatically inferred if one of its argument 
is of type NimNode.
      result = newNimNode(nnkStmtList)
      var
        #section = newNimNode(nnkConstSection)
        section = newNimNode(nnkVarSection)
        constDef = newNimNode(nnkIdentDefs)
      constDef.add(newIdentNode("myvar"))
      constDef.add(newEmptyNode())
      constDef.add(newIdentNode("C" & $c))
      section.add(constDef)
      result.add(section)
    
    const CX = 7
    
    macro t(s: string): typed =
      var hhh = "X"
      #genVar("X")
      genVar($s) # this return a NimNode
      # echo myVar + 1 # this makes no sense inside a macro
      # NimNode are not variable in the traditional sense.
    
    
    t("X")
    echo myVar + 1 # this works
    

Reply via email to