I have stumbled upon interesting use case when length of array I return from 
proc depends on the type of the input argument. From language design 
perspective is it something Nim should support or no? Currently compiler 
crashes. I know it can be done with macro, more of conceptual discussion.
    
    
    proc len(t: tuple|object): int =
      for _ in fields(t):
        inc len
    
    proc fieldNames(t: tuple|object): array[len(t), string] =
      var i = 0
      for name,_ in fieldPairs(t):
        result[i] = name
        inc i
    
    
    let tt = (a: 10, b: 20, c:30)
    echo fieldNames(tt)
    

Reply via email to