Browse files

[Signature] parameter traits and modifiers

  • Loading branch information...
1 parent fe4e68d commit 0fe12365350579254d22977b01d454f2bb79c3d1 @moritz moritz committed Jul 6, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 lib/Signature.pod
@@ -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

0 comments on commit 0fe1236

Please sign in to comment.