Variadic function: Difference between revisions

Add Ecstasy example
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(Add Ecstasy example)
Line 1,026:
println(y)
}</syntaxhighlight>
 
=={{header|Ecstasy}}==
Ecstasy does not support a true variadic function (<i>a la</i> C with "<tt>...</tt>") or a syntactic sugar for the same (<i>a la</i> Java with "<tt>...</tt>" and the underlying <tt>Object[]</tt>). Instead, when a variadic call is needed, the method or function is declared with the desired array type, and the caller simply passes an array value of any length using the literal array syntax:
 
<syntaxhighlight lang="java">
module VariadicFunction
{
void show(String[] strings)
{
@Inject Console console;
strings.forEach(s -> console.println(s));
}
 
void run()
{
show(["hello", "world"]);
 
String s1 = "not";
String s2 = "a";
String s3 = "constant";
String s4 = "literal";
show([s1, s2, s3, s4]);
}
}
</syntaxhighlight>
 
Output:
<syntaxhighlight>
hello
world
not
a
constant
literal
</syntaxhighlight>
 
=={{header|Egel}}==
162

edits