Skip to content

Commit fbfbf48

Browse files
committed
funcitons: talk about return
1 parent 54d8707 commit fbfbf48

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

lib/Language/functions.pod

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,34 @@ are as easy to use and powerful as C<map>.
225225
226226
=head2 Routines
227227
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>.
230231
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+
}
232245
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
234256
235257
=head1 Defining Operators
236258

0 commit comments

Comments
 (0)