Variadic function: Difference between revisions

m
Corrected PL/I and R lang tags
m (Omit from COBOL.)
m (Corrected PL/I and R lang tags)
Line 1,087:
 
=={{header|PL/I}}==
<lang PL/Ipli>/* PL/I permits optional arguments, but not an infinitely varying */
/* argument list: */
s: procedure (a, b, c, d);
Line 1,204:
=={{header|R}}==
This first function, almost completes the task, but the formatting isn't quite as specified.
<lang Rrsplus> printallargs1 <- function(...) list(...)
printallargs1(1:5, "abc", TRUE)
# [[1]]
Line 1,215:
# [1] TRUE</lang>
This function is corrrect, though a little longer.
<lang Rrsplus> printallargs2 <- function(...)
{
args <- list(...)
Line 1,226:
# [1] TRUE</lang>
Use do.call to call a function with a list of arguments.
<lang Rrsplus>arglist <- list(x=runif(10), trim=0.1, na.rm=TRUE)
do.call(mean, arglist)</lang>
 
Anonymous user