I wouldn't recommend using converter as it makes your code less readable and 
can often create ambiguity when compiling, especially for something as trivial 
as an assignment.

You could rewrite your code as this :
    
    
    type SEQ*[T] = object
      data*: seq[T]
    
    proc asSEQ*[T](x: seq[T]) : SEQ[T] =
      result.data = x
    
    proc initSEQ*[T](n: int): SEQ[T] =
      SEQ[T](data: newSeq[T](n))
    
    # [] operator
    proc `[]`*[T](self: SEQ[T], i: int): T =
      self.data[i]
    
    proc `[]=`*[T](self: var SEQ[T], i: int, val: T) =
      var d = self.data
      d[i] = val
    
    # No need to return a if passed as a var parameters
    proc f*[T](a: var SEQ[T]) =
      a[0] = 1
    
    when isMainModule:
      var a: SEQ[int] = @[1, 2, 3].asSEQ # I want to define this way by 
converter
      f(a)
      echo a[0]
    
    
    Run

Reply via email to