I've discovered unpackVarargs, but not really sure how to use it.
Basically, what I want to achieve is: pass a seq of arguments to a function that expects one or more different arguments.
How can I do that?
I know, but I still don't get it how this could help in my case.
Let me elaborate:
proc doSomething(x: int, y: string, z: int): int =
echo "I'm doing something with: " & y
return x + y
; and I have an array like this:
let arr = @[2, "something", 3]
; I want to call the above function - without changing its params - by passing the array above
As was mentioned that's invalid Nim code. At one point I did throw together this macro for someone in the realtime chat which is similar to what you want.
import std/macros
macro `<-`(p: untyped, args: array): untyped =
let
t = args.getType
count = t[1][^1].intval
result = p.copyNimTree
var exprs: seq[NimNode]
for x in 0..count:
result.add nnkBracketExpr.newTree(args, newLit(x))
proc test(a, b, c: int) = discard
let a = [1, 2, 3]
test() <- a
Yep, it is lol
(I guess I got a bit... carried away).