I am trying to inspect a sequence of tuples:
import macros
macro iterateSeq*(elems: typed): untyped =
var tmp = elems.getTypeImpl
for elem in tmp[1]:
var t = elem.getTypeImpl
echo "--> ", t.treeRepr
let elems = @[ ( x: 111, y: 222, name: "aa" ),
( x: 2, y: 5, name: "kak" ),
( x: 8, y: 1, name: "oo" ),
( x: 11, y: 8, name: "jos" ) ]
iterateSeq(elems)
but it seems like I am getting just 3 instead of 4 tuples:
--> TupleTy
IdentDefs
Sym "x"
Sym "int"
Empty
IdentDefs
Sym "y"
Sym "int"
Empty
IdentDefs
Sym "name"
Sym "string"
Empty
--> TupleTy
IdentDefs
Sym "x"
Sym "int"
Empty
IdentDefs
Sym "y"
Sym "int"
Empty
IdentDefs
Sym "name"
Sym "string"
Empty
--> TupleTy
IdentDefs
Sym "x"
Sym "int"
Empty
IdentDefs
Sym "y"
Sym "int"
Empty
IdentDefs
Sym "name"
Sym "string"
Empty
What am I missing?
You are looping through the AST of the type, not the actual sequence.
May be you need getImpl instead of getTypeImpl? https://play.nim-lang.org/#ix=3nWa