You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import spread
procfooImpl(a, b, c, d: int) =echo a + b + c + d
templatefoo(args: untyped) =spread(fooImpl, args)
# or, to keep regular call syntax working:from macros import unpackVarargs
templatefoo(args: varargs[untyped]) =
spread.unpackVarargs(fooImpl, args)
foo:
a =1
b =2
c =3
d =4
The limitations are that foo needs an untyped parameter due to the normally invalid a = 1 etc statements, which means it can't be passed around as a proc value; and foo and fooImpl can't have the same name i.e. overload each other, because the fooImpl overload will have a typed parameter where the untyped argument is supposed to be which will again cause it to get typechecked.
As long as these limitations are acknowledged though, a way to generate these could be nice, maybe as simple as adding {.spread.} to a proc
Say I have an existing procedure like this:
Is it possible to use
spread
to create a version of this procedure (with the same name) that takes a body of arguments?The text was updated successfully, but these errors were encountered: