I'm working on a little library with a bunch of distinct string types. Using the advice in the manual, I made a template to define the string operations I need:
template defineStrOprs(typ: typedesc) =
proc `$`*(x: typ): string {.borrow.}
proc `&`*(x, y: typ): typ = typ($x & $y)
proc `&=`*(x: var typ, y: typ) {.borrow.}
proc `[]`*[T, U](x: typ; h: HSlice[T, U]): typ = typ(($x)[h])
...
When I run nim doc, I get "gensym'd" arguments:
proc `$`(x`gensym12636101: Dna): string {...}
I'm concerned downstream users of this library (likely to be novices) will be put off. Is there a way to remove it from the docs?
read over https://nim-lang.org/docs/manual.html#templates-hygiene-in-templates for a better explanation of {.dirty.} {.gensym.} and {.inject.}
{.dirty.} is probably the best solution for your case, otherwise you have to annotate everything with {.inject.}
template defineStrOprs(typ: typedesc) =
proc `$`*(x:{.inject.} typ): string {.borrow.}
proc `&`*(x{.inject.}, y{.inject.}: typ): typ = typ($x & $y)
proc `&=`*(x{.inject.}: var typ, y{.inject.}: typ) {.borrow.}
proc `[]`*[T, U](x{.inject.}: typ; h{.inject.}: HSlice[T, U]): typ = typ(($x)[h])