parameter *@

Documentation for parameter *@ assembled from the following types:

class Signature

From Signature

(Signature) parameter *@

A function is variadic if it can take a varying number of arguments; that is, its arity is not fixed. Therefore, optional, named, and slurpy parameters are variadic. An array or hash parameter can be marked as slurpy by leading asterisk (*) or two leading asterisks (**) or a leading plus (+). A slurpy parameter can bind to an arbitrary number of arguments (zero or more).

These are called "slurpy" because they slurp up any remaining arguments to a function, like someone slurping up noodles.

$ = :($a@b);     # exactly two arguments, where the second one must be Positional 
$ = :($a*@b);    # at least one argument, @b slurps up any beyond that 
$ = :(*%h);        # no positional arguments, but any number of named arguments 
sub one-arg (@)  { }
sub slurpy  (*@) { }
one-arg (567); # ok, same as one-arg((5, 6, 7)) 
slurpy  (567); # ok 
slurpy   567 ; # ok 
# one-arg(5, 6, 7) ; # X::TypeCheck::Argument 
# one-arg  5, 6, 7 ; # X::TypeCheck::Argument 
sub named-names (*%named-args{ %named-args.keys };
say named-names :foo(42:bar<baz># OUTPUT: «foo bar␤» 

Note that positional parameters aren't allowed after slurpy parameters.

# ===SORRY!=== Error while compiling: 
# Cannot put required parameter $last after variadic parameters 

Normally a slurpy parameter will create an Array, create a new Scalar container for each argument, and assign the value from each argument to those Scalars. If the original argument also had an intermediary Scalar it is bypassed during this process, and is not available inside the called function.

Slurpy parameters have special behaviors when combined with some traits and modifiers, as described in the section on slurpy array parameters.