Task

Create a function which takes in a variable number of arguments and prints each one on its own line.

Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.



Functions of this type are also known as Variadic Functions.



Related task

   Call a function


void local fn Function1( count as long, ... )
  va_list ap
  long value
 
  va_start( ap, count )
  while ( count )
    value = fn va_argLong( ap )
    printf @"%ld",value
    count--
  wend
 
  va_end( ap )
end fn
 
void local fn Function2( obj as CFTypeRef, ... )
  va_list ap
 
  va_start( ap, obj )
  while ( obj )
    printf @"%@",obj
    obj = fn va_argObj(ap)
  wend
 
  va_end( ap )
end fn
 
window 1
 
// params: num of args, 1st arg, 2nd arg, etc.
fn Function1( 3, 987, 654, 321 )
 
print
 
// params: 1st arg, 2nd arg, ..., NULL
fn Function2( @"One", @"Two", @"Three", @"O'Leary", NULL )
 
HandleEvents