In Raku, parameters can be either positional or named parameters (declared with the colon-pair syntax). However, from what I understand, only positional parameters can be passed as positional and named parameters as named. The closest Raku subroutine to Python's `def fun(a, b, c=None)` would be:<p><pre><code> sub fun($a, $b, :$c) { }
fun(1, 2) # This works!
fun(1, 2, 3) # Error: Too many positionals passed...
fun(:a(1), :b(2), :c(3)) # Error: Too few positionals passed...
fun(:c(3), :a(1), :b(2)) # Same as before
fun(:c(3), 1, 2) # This works!
</code></pre>
Positional parameters are required by default but they can be made optional
by providing a default value in the subroutine's signature or by placing
a `?` right after the parameter. However, much like Python, positional parameters
must appear before optional parameters:<p><pre><code> sub fun($b, $a?, :$c) { }
fun(1) # This works!
</code></pre>
On the other hand, named parameter, as evidenced by the first code snippet,
are optional. However, they can be made required by placing a `!` right after
the parameter:<p><pre><code> sub fun($a, $b, :$c!) { }
fun(1, 2) # Error: Required named parameter 'c' not passed
fun(1, 2, :c(3)) # This works!
</code></pre>
Remaining arguments can be slurped by using slurpy parameters. In its most basic form, slurpy positional parameters are indicated with `A` followed by an array parameter:<p><pre><code> sub fun($a, $b, A@rest) { }
</code></pre>
However, regardless of the structure of the arguments, they are flatten. This automatic flattening can be avoided by using `AA` instead. Or it can be done conditionally by using `+`: If there's a single argument, flaten it. Else, leave them alone.<p>Slurpy named parameters are indicated also with `A` followed by a hash parameter:<p><pre><code> sub fun(:$c, :$d, A%rest) { }
</code></pre>
Both can be used in conjunction:<p><pre><code> sub fun($a, $b, :$c, :$d, A@rest, A%rest) { } # Or:
sub fun($a, $b, A@rest, :$c, :$d, A%rest) { }
</code></pre>
Edit: HN eats up the asterisks so using `A` to stand for asterisk.