Thanks all @PMunch , choltreppe, and @nrk! @nrk I'd seen those docs, but I couldn't see why even the proc parameters would be gensym'd. Is there a way to actually see the expanded Nim code. Like your comment: # works, as it expands to something like: # let x`gensym0 = "hello world" # echo x`gensym0 # let x`gensym1 = "dlrow olleh" # echo x`gensym1 Run
could I actually see that without getting headed off by compiler errors? Kind of like how `dumpAst` works but without having to do it in the macro (which now somehow seem clearer than templates to me). Thanks to all the help here I was able to apply some of this very simply to a toy parsing project with `{.inject.}` (which I have asked other question for in the forum)! template step*(input: untyped): untyped = (`input`).parse_partial(stream, index) template generate(body: untyped): untyped = block: proc temp[T, R](stream{.inject.}: Stream[T], index{.inject.}: var int): Result[R] = `body` Parser(fn: temp, description: "") let t: Parser[char, string] = generate: let x = step test_string("he") discard step "ll" let s = step "o" return x&s echo t.parse("hello") Run Any idea why with the templates, I get this message about mismatched types: type mismatch: got 'Parser' for 'block: proc temp[T; R](stream: Stream[T]; index: var int): Result[R] = let x = (test_string("he")).parse_partial(stream, index) discard ("ll").parse_partial(stream, index) let s = ("o").parse_partial(stream, index) return x & s Parser(fn: temp, description: "")' but expected 'Parser[system.char, system.string]' Run I don't see any ambiguity in the typings with `let t: Parser[char, string]`. Without the type on `t` I get other errors about ambiguity not mis-match. I also tried just adding types to the template with `template generate(T, R: typedesc; body: untyped)` and `template generate(T, R: untyped; body: untyped)` which brought other problems where the errors suggested (in the first case) that the types were bound to the `temp` proc in some way (like type mismatch got `temp.char` expected `system.char`...)