Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Signature] parameter traits and modifiers
  • Loading branch information
moritz committed Jul 6, 2012
1 parent fe4e68d commit 0fe1236
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/Signature.pod
Expand Up @@ -130,6 +130,34 @@ notionally) computed anew for each call
:($goal, $accuarcy = $goal / 100);
:(:$excludes = ['.', '..']); # a new Array for every call
=head2 Parameter Traits and Modifiers
By default, parameters are bound to their argument and marked as
read-only. One can change that with traits on the parameter.
The C<is copy> trait causes the argument to be copied, and allows it
to be modified inside the routine
sub c($x is copy) {
$x = Inf if $x ~~ Whatever;
.say for 1..$x;
}
The C<is rw> trait makes the parameter only bind to a variable (or other
writable container)N<this does not work yet in Rakudo>. Assigning to the
parameter changes the value of the variable at the caller side
sub swap($x is rw, $y is rw) {
($x, $y) = ($y, $x);
}
To bind either to a value or a variable, one can prefix a parameter with
a backslash C<\>.
sub f(\$raw) { ... }
Prefixing a parameter with a vertical bar C<|> makes it use up all the
remaining positional and named arguments.
=head1 Methods
Expand Down

0 comments on commit 0fe1236

Please sign in to comment.