One way is to capture all elements into a sequence and then iterate over it: import std/[macros, sequtils] macro xyz(body: untyped): untyped = let children = toSeq(body.items()) for child in children[1 .. ^1]: echo child.astGenRepr xyz: var q = 1 var p = 2 var r = 3 Run
Don't forget that you can use almost all of Nim stdlib during compile-time :)