@@ -225,12 +225,34 @@ are as easy to use and powerful as C<map>.
225
225
226
226
= head2 Routines
227
227
228
- TODO
229
- = comment return from sub and return from block
228
+ Routines are code objects that conform to L < type Routine|/type/Routine > , most
229
+ notably L < Sub|/type/Sub > , L < Method|/type/Method > , L < Regex|/type/Regex > and
230
+ L < Submethod|/type/Submethod > .
230
231
231
- = comment Important ones: candidates, wrap, unwrap, assuming, arity, count
232
+ They carry additional functionality in addition to what L < Block|/type/Block >
233
+ supplies: they can come as L < multis|#Multi-dispatch > ,
234
+ you can L < wrap|/type/Routine#method warp > them, and exit early with C < return > :
235
+
236
+ = begin code :allow<B>
237
+ my $keywords = set <if for unless while for>;
238
+
239
+ sub has-keyword(*@words) {
240
+ for @words -> $word {
241
+ B < return > True if $word (elem) $keywords;
242
+ }
243
+ False;
244
+ }
232
245
233
- = comment link to Routine documentation (?)
246
+ say has-keyword 'not', 'one', 'here'; # False
247
+ say has-keyword 'but', 'here', 'for'; # True
248
+ = end code
249
+
250
+ Here C < return > does not just leave the block inside which it was called, but
251
+ the whole routine. In general, blocks are transparent to C < return > , they
252
+ attach to the outer routine.
253
+
254
+
255
+ = comment Important ones: candidates, wrap, unwrap, assuming, arity, count
234
256
235
257
= head1 Defining Operators
236
258
0 commit comments