Perl 5 style is still supported.
Named parameters go into %_
Unnamed parameters go into @_
Subroutines can be predefined with:
sub foo {…}
… is known as the "yadayadayada" operator.
Lexically scoped subroutines:
my sub mysub () is context { …}
Optional parameters: ? now comes after the parameter name.
sub mysub ($value, @harry, %ash, $opt?) {…}
Named parameters: prefix is now : , instead of + and are optional unless they have a ! suffix.
sub named ($value, :@harry!, :%ash, :$other) {…}
...
named(42, other = 'fred', harry = @files);
Slurpy parameters, like perl 5 lists and arrays, are prefixed *
C style prototypes
Are not supported. It appears that when a subroutine is called before it is defined the parameter resolution still works correctly. However a runtime error is reported, not a compile time error (as it would with Perl 5 prototypes).
Dynamic types
These are called "traits". See Synopsis 12: Objects.
Zip operator
Has changed, it is now 'Z'. Behaviour with different length arrays has also changed between pugs and Rakudo, the result uses the shortest:
my @array = qw(The quick brown fox);
my @brray = qw(Now is the time for all);
my @all = @array Z @brray;
say @all.elems();
say @all[];
@all = @brray Z @array;
say @all.elems();
say @all[];
Gives:
8
TheNowquickisbrownthefoxtime
8
NowTheisquickthebrowntimefox
Important further change
When testing these changes in Rakudo I ran up against a change I had almost forgotten. When calling a subroutine, no whitespace is allowed between the sub name and the open parentheses. That slowed me up until I remembered. A backward step IMHO.
No comments:
Post a Comment