.. default-domain:: chpl .. _primers-varargs: Variadic Arguments ================== `View varargs.chpl on GitHub `_ This primer demonstrates procedures with variable length arguments lists. Procedures can be defined with variable length argument lists. The following procedure accepts integer arguments and defines the parameter ``n`` as the number of arguments passed to the current call. The args argument is an ``n``-tuple of ``int`` values. .. code-block:: chapel proc intWriteln(args: int ...?n) { for i in args.indices { if i != n-1 then write(args(i), " "); else writeln(args(i)); } } intWriteln(1, 2, 3, 4); By eliding the type of the ``args`` argument, the variable arguments can be made generic. The following procedure takes ``n`` arguments of any type and writes them on a single line. Here, ``args`` is a heterogeneous ``n``-tuple, so a parameter for loop is used to unroll the loop body so that the index ``i`` is a parameter and each ``write()`` call can be instantiated independently. .. code-block:: chapel proc anyTypeWriteln(args...?n) { for param i in 0..