Variadic function: Difference between revisions

m
{{header|F Sharp|F#}}
m ({{header|F Sharp|F#}})
 
(8 intermediate revisions by 6 users not shown)
Line 1,067:
 
=={{header|Elena}}==
ELENA 46.1x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 1,075:
printAll(params object[] list)
{
for(int i := 0,; i < list.Length,; i+=1+)
{
self.printLine(list[i])
Line 1,214:
 
print_args({"Mary", "had", "a", "little", "lamb"})</syntaxhighlight>
 
=={{header|F Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Variadic function. Nigel Galloway: March 6th., 2024
open System
type X()=static member F([<ParamArray>] args: Object[]) = args|>Array.iter(printfn "%A")
X.F(23, 3.142, "Nigel", 1u, true)
</syntaxhighlight>
{{output}}
<pre>
23
3.142
Nigel
1
true
</pre>
 
=={{header|Factor}}==
Line 1,333 ⟶ 1,349:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Variadic_function}}
 
'''Solution'''
 
Fōrmulæ does not have variadic functions. However an array can be provided as argument:
 
'''Examples'''
 
Tee following function accepts a list as its unique parameter. It retrieves the list in vertical form (as a matrix of 1 column):
 
[[File:Fōrmulæ - Variadic function 01.png]]
 
[[File:Fōrmulæ - Variadic function 02.png]]
 
[[File:Fōrmulæ - Variadic function 03.png]]
 
[[File:Fōrmulæ - Variadic function 04.png]]
 
[[File:Fōrmulæ - Variadic function 05.png]]
 
With this approach we can use several parameters being lists with variable number of elements each, for example:
 
[[File:Fōrmulæ - Variadic function 06.png]]
 
[[File:Fōrmulæ - Variadic function 07.png]]
 
[[File:Fōrmulæ - Variadic function 08.png]]
 
=={{header|FutureBasic}}==
Line 1,491 ⟶ 1,533:
c
d</pre>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(function f
(print (join "\n" args)))
 
(f 1 2 3 4)</syntaxhighlight>
 
=={{header|Io}}==
Line 2,823 ⟶ 2,871:
[1 2 3] 6
[1 2 3 4] 10
</pre>
 
=={{header|RPL}}==
Variable number of arguments are idiomatically passed through the stack, with the last argument specifying how many items shall be taken into account.
{{works with|HP|48G}}
≪ ""
1 ROT '''START'''
" " ROT + SWAP +
'''END''' TAIL
≫ '<span style="color:blue">MKLINE</span>' STO
 
"Mary" "has" "a" "little" "lamb" 5 <span style="color:blue">MKLINE</span>
{{out}}
<pre>
1: "Mary has a little lamb"
</pre>
 
Line 3,151 ⟶ 3,214:
=={{header|Wren}}==
Wren doesn't support variadic functions and doesn't really need to as we can just write a function which takes one (or one more) argument and pass it a list.
<syntaxhighlight lang="ecmascriptwren">var printArgs = Fn.new { |args| args.each { |arg| System.print(arg) } }
 
printArgs.call(["Mary", "had", "3", "little", "lambs"])</syntaxhighlight>
2,171

edits