![]() |
An example of slurpy parameters
|
|
|
|
An example of slurpy parameters
sub head(*$head, *@tail) { return $head }
sub neck(*$head, *$neck, *@tail) { return $neck }
sub tail(*$head, *@tail) { return @tail }
my @args = (1..5);
# $head parameter receives 1
# @tail parameter receives [2, 3, 4, 5]
head(@args).say;
# $head parameter receives 1
# $neck parameter receives 2
# @tail parameter receives [3, 4, 5]
neck(@args).say;
# $head parameter receives 1
# @tail parameter receives [2, 3, 4, 5]
tail(@args).say;
So now, we are comfortable with taking apart a list which is passed to
a sub. A lot of functional programming revolves around taking apart a
list and doing things with the parts... so let's see some functional
programming in Perl 6
Slurpy Sub Parms, Multi Subs and Perl 6 Functional Programming
Terrence Brannon
(2005-03-08)
|
|