@@ -266,13 +266,14 @@ happy-birthday( 'Jack', 25 ); # OUTPUT: «Happy 25th Birthday J
266
266
267
267
= end code
268
268
269
- The first two versions of the C < happy-birthday > sub differs only in the arity (number of
270
- arguments), while the third version uses named arguments and is chosen only when named
271
- arguments are used, even if the arity is the same of another C < multi > candidate.
269
+ The first two versions of the C < happy-birthday > sub differs only in the arity
270
+ (number of arguments), while the third version uses named arguments and is
271
+ chosen only when named arguments are used, even if the arity is the same of
272
+ another C < multi > candidate.
272
273
273
- When two sub have the same arity, the type of the arguments drive the dispatch; when
274
- there are named arguments they drive the dispatch even when their type is the same as another
275
- candidate:
274
+ When two sub have the same arity, the type of the arguments drive the dispatch;
275
+ when there are named arguments they drive the dispatch even when their type is
276
+ the same as another candidate:
276
277
277
278
= begin code
278
279
multi happy-birthday( Str $name, Int $age ) {
@@ -334,8 +335,8 @@ object:
334
335
$congrats.congratulate('promotion','Cindy'); # OUTPUT: «Hooray for your promotion, Cindy»
335
336
$congrats.congratulate('birthday','Bob'); # OUTPUT: «Happy birthday, Bob»
336
337
337
- Unlike C < sub > , if you use named parameters with multi methods, the parameters must
338
- be required parameters to behave as expected.
338
+ Unlike C < sub > , if you use named parameters with multi methods, the parameters
339
+ must be required parameters to behave as expected.
339
340
340
341
Please note that a non-multi sub or operator will hide multi candidates of the
341
342
same name in any parent scope or child scope. The same is true for imported
@@ -360,10 +361,11 @@ arguments. Consider this basic example:
360
361
= for code :skip-test
361
362
congratulate('being a cool number', 42); # Proto match error
362
363
363
- The proto insists that all C < multi congratulate > conform to the basic signature of two strings,
364
- optionally followed by further parameters. The C < | > is an un-named C < Capture >
365
- parameter, and allows a C < multi > to take additional arguments. The first two calls
366
- succeed, but the third fails (at compile time) because C < 42 > doesn't match C < Str > .
364
+ The proto insists that all C < multi congratulate > conform to the basic signature
365
+ of two strings, optionally followed by further parameters. The C < | > is an
366
+ un-named C < Capture > parameter, and allows a C < multi > to take additional
367
+ arguments. The first two calls succeed, but the third fails (at compile time)
368
+ because C < 42 > doesn't match C < Str > .
367
369
368
370
= for code :skip-test
369
371
say &congratulate.signature # OUTPUT: «(Str $reason, Str $name, | is raw)»
@@ -402,13 +404,12 @@ many modules, will follow.
402
404
403
405
= head2 Slurpy Conventions
404
406
405
- Perhaps the most important one of these conventions is the way slurpy list arguments are
406
- handled. Most of the time, functions will not automatically flatten
407
- slurpy lists.
408
- The rare exceptions are those functions that don't have a
409
- reasonable behavior on lists of lists (e.g., L < chrs|/routine/chrs > )
410
- or where there is a conflict with an established idiom (e.g., L < pop|/routine/pop >
411
- being the inverse of L < push|/routine/push > ).
407
+ Perhaps the most important one of these conventions is the way slurpy list
408
+ arguments are handled. Most of the time, functions will not automatically
409
+ flatten slurpy lists. The rare exceptions are those functions that don't have a
410
+ reasonable behavior on lists of lists (e.g., L < chrs|/routine/chrs > ) or where
411
+ there is a conflict with an established idiom (e.g., L < pop|/routine/pop > being
412
+ the inverse of L < push|/routine/push > ).
412
413
413
414
If you wish to match this look and feel, any L < Iterable|/type/Iterable > argument must
414
415
be broken out element-by-element using a C < **@ > slurpy, with two nuances:
@@ -532,7 +533,7 @@ Routines are code objects that conform to L<type Routine|/type/Routine>, most
532
533
notably L < Sub|/type/Sub > , L < Method|/type/Method > , L < Regex|/type/Regex > and
533
534
L < Submethod|/type/Submethod > .
534
535
535
- They carry additional functionality in addition to what L < Block|/type/Block >
536
+ They carry extra functionality in addition to what L < Block|/type/Block >
536
537
supplies: they can come as L < multis|#Multi-dispatch > ,
537
538
you can L < wrap|/type/Routine#method_wrap > them, and exit early with C < return > :
538
539
@@ -550,7 +551,7 @@ you can L<wrap|/type/Routine#method_wrap> them, and exit early with C<return>:
550
551
551
552
Here, C < return > doesn't just leave the block inside which it was called, but
552
553
the whole routine. In general, blocks are transparent to C < return > , they
553
- attach to the outer routine.
554
+ attach to the outermost routine.
554
555
555
556
X < |use soft (pragma) >
556
557
Routines can be inlined and as such provide an obstacle for wrapping. Use the
@@ -643,13 +644,13 @@ prefix the operator name with a C<&>-sigil.
643
644
say "abc" ieq "Abc";
644
645
# OUTPUT: «True»
645
646
647
+ X « |is tighter » X « |is equiv » X « |is looser »
646
648
= head2 Precedence
647
649
648
- X « |is tighter » X « |is equiv » X « |is looser »
649
- Operator precedence in Perl 6 is specified relatively to existing operators.
650
- The traits C < is tighter > , C < is equiv > and C < is looser > can be provided with an
651
- operator, the new operators precedence is related to. More than one trait can
652
- be applied.
650
+ Operator precedence in Perl 6 is specified relatively to existing operators. The
651
+ traits C < is tighter > , C < is equiv > and C < is looser > can be provided with an
652
+ operator to indicate how the precedence of the new operators is related to
653
+ other, existing ones. More than one trait can be applied.
653
654
654
655
For example, C « infix:<*> » has a tighter precedence than C « infix:<+> » ,
655
656
and squeezing one in between works like this:
@@ -740,12 +741,13 @@ class SomeClass does AnotherRole { ... }
740
741
has $!another-attribute handles <close>;
741
742
# ^^^^^^^ trait
742
743
743
- ... and also C < is tighter > , C < is looser > , C < is equiv > and C < is assoc > from the previous
744
- section.
744
+ ... and also C < is tighter > , C < is looser > , C < is equiv > and C < is assoc > from the
745
+ previous section.
745
746
746
747
Traits are subs of the form C << trait_mod<VERB> >> , where C < VERB > stands for the
747
748
name like C < is > , C < does > or C < handles > . It receives the modified thing as
748
- argument, and the name as a named argument. See L < Sub|/type/Sub#Traits > for details.
749
+ argument, and the name as a named argument. See L < Sub|/type/Sub#Traits > for
750
+ details.
749
751
750
752
= begin code
751
753
multi sub trait_mod:<is>(Routine $r, :$doubles!) {
0 commit comments