@@ -149,8 +149,9 @@ as the parameters were declared.
149
149
In the case of named arguments and parameters, only the name is used for
150
150
mapping arguments to parameters
151
151
152
+ = for code :allow<L>
152
153
sub named(:$x, :$y) { "x=$x y=$y" }
153
- named( y => 5, x => 4); # x=4 y=5
154
+ named( y L « => » 5, x => 4); # x=4 y=5
154
155
155
156
It is possible to have a different name for a named parameter than the
156
157
variable name:
@@ -163,28 +164,38 @@ Aliases are also possible that way:
163
164
sub paint( :color(:colour($c)) ) { } # 'color' and 'colour' are both OK
164
165
sub paint( :color(:$colour) ) { } # same API for the caller
165
166
166
-
167
167
= head2 Optional and Mandatory Parameters
168
168
169
- Named parameters are optional by default, and can be made mandatory with a
170
- trailing exclamation mark:
171
-
172
- :(:$name!) # mandatory 'name' named parameter
173
-
174
169
Positional parameters are mandatory by default, and can be made optional
175
170
with a default value or a trailing question mark:
176
171
172
+ :(Str $id) # required parameter
177
173
:($base = 10) # optional parameter, default value 10
178
174
:(Int $x?) # optional parameter, default is the Int type object
179
175
180
- Named parameters can also have default values.
176
+ Named parameters are optional by default, and can be made mandatory with a
177
+ trailing exclamation mark:
178
+
179
+ :(:%config) # optional parameter
180
+ :(:$debug = False) # optional parameter, defaults to False
181
+ :(:$name!) # mandatory 'name' named parameter
181
182
182
183
Default values can depend on previous parameters, and are (at least
183
184
notionally) computed anew for each call
184
185
185
186
:($goal, $accuracy = $goal / 100);
186
187
:(:$excludes = ['.', '..']); # a new Array for every call
187
188
189
+ = head2 Capture Parameters
190
+
191
+ Prefixing a parameter with a vertical bar C < | > makes the parameter a
192
+ L < C < Capture > > , using up all the remaining positional and named
193
+ arguments.
194
+
195
+ This is often used in L < C < proto > definitions|proto> (like C < proto foo (|) {*} > )
196
+ to indicate that the routine's L < C < multi > definitions|multi> can have any
197
+ L < type constraints|#Type_Constraints > .
198
+
188
199
= head2 Parameter Traits and Modifiers
189
200
190
201
By default, parameters are bound to their argument and marked as
@@ -206,14 +217,6 @@ value of the variable at the caller side
206
217
($x, $y) = ($y, $x);
207
218
}
208
219
209
- To bind either to a value or a variable, one can prefix a parameter with
210
- a backslash C < \ > .
211
-
212
- sub f(\$raw) { ... }
213
-
214
- Prefixing a parameter with a vertical bar C < | > makes it use up all the
215
- remaining positional and named arguments.
216
-
217
220
= head1 Methods
218
221
219
222
= head2 method params
0 commit comments