Is there a way to have optional params before an untyped body in templates/macros?
The last case gives an error, that's the one I want:
template foo(a1 = 10, a2 = "", body: untyped) = discard
# works
foo(3, "asdf"):
for a in 0..<3:
echo a
echo 10
foo(body = (echo 10))
# doesn't work: Error: type mismatch: got <void>
foo():
for a in 0..<3:
echo a
echo 10
The rule could be: allow optional typed parameters before an untyped statement list; it would be un-ambiguous.
Workarounds are not great:
with this PR https://github.com/nim-lang/Nim/pull/11754 we can do it as follows:
dispatch foo:
for a in 0..<3:
echo a
echo 10