You could do import macros macro setDocComment(a : static[string]) : untyped = result = nnkCommentStmt.newTree() result.strVal = a template foo(fn: untyped, doc: static[string]) = proc fn*(a: Foo) = setDocComment(doc) callfunc(fn, a) Run
though it only immediately calls the macro setDoc if fn is a non generic proc For a template or generic proc you could instead do import macros macro foo(fn: untyped, doc: static[string]) = let docString = nnkCommentStmt.newTree() docString.strVal = doc result = quote do: proc `fn`*(a: Foo) = `docString` callfunc(`fn`, a) Run