proc myWriteln(f: File, a: varargs[string]) =
for s in items(a):
write(f, s)
write(f, "\n")
myWriteln(stdout, "abc", "def", "xyz")
# is transformed by the compiler to:
myWriteln(stdout, ["abc", "def", "xyz"])
This transformation is only done if the varargs parameter is the last parameter in the procedure header. but
proc myWriteln(a:varargs[string],b:string)=
for i in 0..len(a)-1:
echo a[i]
myWriteln("abc","def","xyz","123")
This case is also correct! So how to understand varargs parameter?proc myWriteln(a:varargs[string],b:string)=
for i in 0..len(a)-1:
echo a[i]
echo b
myWriteln("abc","def","xyz","123")
This is also correct!
proc myWriteln(a:varargs[string],f:File)=
for s in items(a):
writeln(f,s)
myWriteln("abc","def","xyz",stdout)
I don't think there will be a problem, I just don't understand this sentence!