Ege Özpınar
Ege Özpınar

Reputation: 31

How can I use var args(variadic arguments) in a function?

I tried something like

proc foo(args...?n) {
  var x = max(args);
  return x;
}

but it didn't work.

Upvotes: 2

Views: 57

Answers (1)

Ege Özpınar
Ege Özpınar

Reputation: 31

When I asked the question at the above in the Chapel gitter channel, they gave me the answer at the below. And it worked.

var args actuals can be used as tuples. So unless max is a function that takes tuples as args that won’t work. If max is also a var args function, you have to pass the elements of tuples one-by-one. However, there is tuple expansion in chapel and the syntax is (...args) including the parentheses so the problematic line should be var x = max((...args))

Upvotes: 1

Related Questions