I noticed bind no longer works in generic procs. I came up with a macro that
can be used as a pragma workaround.
macro genProcWithBind*(a : untyped) : untyped =
let templateSym = genSym(nskTemplate)
let body = a[6].copy()
let newProc = a.copy()
newProc[6] = quote do:
`templateSym`()
result = newStmtList()
result.add quote do:
template `templateSym`() : untyped =
`body`
result.add newProc
Run
You use it like this.
when false:
#now works with bind
proc sort*[T](a : T) {.genProcWithBind.} =
bind privateSort
privateSort(a)
#turns into this
template genSymed() : untyped =
bind privateSort
privateSort(a)
proc sort*[T](a : T) =
genSymed()
Run
Should work with mixin too. I though it might be useful; maybe even add it to
the system or macros module with a better name then I came up with.