We have "is" and "of" in Nim for static and dynamic type tests.

Note that your custom names "String" and "Integer" may be a bit confusing, as 
people unfamiliar with Nim may guess that that are basic Nim types.

This code works for me:
    
    
    import strutils, typetraits, unicode
    
    type
      Token = object of RootObj
      Integer = ref object of Token
      String = ref object of Token
      
      X = ref object of Integer # inheritance
    
    let d = Integer()
    let c = String()
    
    #
    
    var t: Token
    echo t is Token
    echo d is Integer
    echo c is String
    
    var x: X
    new x
    
    var s = newSeq[Integer]()
    s.add(x)
    echo s[0] is X # false, because static base type of is is seq[Token]
    echo s[0] of X # true, dynamik test
    
    echo name(type(x))
    
    
    
    Run
    
    
    $ ./t
    true
    true
    true
    false
    true
    X
    
    
    Run

Note that Nim is statically typed, so dynamically runtime type test are 
generally only used for OOP design with inheritance, which is not used that 
much in Nim.

You may tell us exactly what you want to archive, then you may get a more 
concrete answer. 

Reply via email to