@zuko95, CMIIW, you can do it like this
    
    
    import typeinfo
    
    type
      Person = ref object
        age: int
        name: string
    
    var people = newSeq[Person]()
    
    proc `$`(p: Person): string =
      p.name & " is " & $p.age & " years old"
    
    proc refFromAnotherScope() =
      people.add Person(name: "scoped general", age: 30)
    
    proc main =
      var s = Person(name: "general", age: 50)
      echo s
      
      case s.toAny.kind
      of akRef:
        echo "s is reference type"
      else:
        echo "s is something else"
      
      echo()
      refFromAnotherScope()     # define Person from another function
      
      echo people[0]
      case people[0].toAny.kind
      of akRef:
        echo people[0].name, " is reference type"
      else:
        echo people[0], " is something else"
    
    
    main()
    

Reply via email to