Both of these work and are probably what he intended to do. 
    
    
    template someCode(name: untyped): untyped =
      var fname {.inject.} = "Mark"
      var age {.inject.} = 44
      type name = object
        fname: string
        age: int
    
    
    someCode somename
    
    
    Run
    
    
    template someCode(name: untyped): untyped {.dirty.} =
      var fname = "Mark"
      var age = 44
      type name = object
        fname: string
        age: int
    
    
    someCode somename
    
    
    Run

  * So the problem is it's trying to use gensymed variable names as field names.
  * If you really want the variables and fields to have the same name and not 
have access to the variables outside of the template invocation.


    
    
    import macros
    macro someCode(name : untyped) : untyped =
      var fname = ident"fname"
      var age = ident"age"
      result = quote do:
        var fname = "Mark"
        var age = 44
        type `name` = object
          `fname`: string
          `age` : int
      #echo treeRepr result
      #echo repr result
    
    someCode somename
    
    
    Run

Reply via email to