I have a template like:
template doSomething(code: untyped) =
... the template ...
which I can call like:
doSomething:
... my code ...
What if I want to add an optional param to this template? Like:
template doSomething(code: untyped, someVar: bool = false) =
... the template ...
How do I call this one?
The compiler seems to handle it fine, although I have trouble calling it.
I've tried:
doSomething(someVar=true):
... my code ...
but it doesn't look like valid syntax.
Any suggestions?
Unfortunately at the moment, untyped parameters need to be at the exact same position when overloading or on template calls https://github.com/nim-lang/Nim/issues/9414
At the moment you need to use the do notation if you keep this order which lead to a strange
doSomething:
... my code ...
do: true # or maybe do true
Code block arguments are always the last argument, so foo(a): x translates to foo(a, x).
template doSomething(someVar: bool = false, code: untyped) =
... the template ...