Skip to content

Instantly share code, notes, and snippets.

@zah
Created August 31, 2011 18:37
Show Gist options
  • Save zah/1184313 to your computer and use it in GitHub Desktop.
Save zah/1184313 to your computer and use it in GitHub Desktop.
proc apply[OpSymbol, T: tuple](t: T) : auto =
macro:
var retType = newNimrodType(ntkTuple)
for fields in T:
retType.add(inferType(newCall(OpSymbol, T[1])) #skiping some detail
var transformedExp = .. build and expression of the type (OpSymbol(T[0]), OpSymbol(T[1]), )
template:
var x : retType = transformedExp
return x
macro getTransformedTupleType(t: symbol) {.late.} =
# the same code
proc apply ... = type(getTransformedTupleType(t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment