@@ -21,33 +21,6 @@ on the C<anon> declarator|/language/variables#The_anon_declarator> for more
21
21
information.
22
22
23
23
24
- X < |is default (Routine) >
25
- = head2 X < Trait is default >
26
-
27
- There is a special trait for C < Routine > s called C < is default > . This trait is
28
- designed as a way to disambiguate C < multi > calls that would normally throw an
29
- error because the compiler would not know which one to use. This means that
30
- given the following two C < Routine > s, the one with the C < is default > trait will
31
- be called.
32
-
33
- multi sub f() is default { say "Hello there" }
34
- multi sub f() { say "Hello friend" }
35
- f(); # OUTPUT: «"Hello there"»
36
-
37
- The C < is default > trait can become very useful for debugging and other uses but
38
- keep in mind that it will only resolve an ambiguous dispatch between two
39
- C < Routine > s of the same precedence. If one of the C < Routine > s is narrower than
40
- another, then that one will be called. For example:
41
-
42
- = begin code
43
- multi sub f() is default { say "Hello there" }
44
- multi sub f(:$greet) { say "Hello " ~ $greet }
45
- f(); # "Use of uninitialized value $greet..."
46
- = end code
47
-
48
- In this example, the C < multi > without C < is default > was called because it was
49
- actually narrower than the C < Sub > with it.
50
-
51
24
= head1 Methods
52
25
53
26
= head2 method name
@@ -358,6 +331,36 @@ TODO: explain export tags
358
331
359
332
= end comment
360
333
334
+ X < |is default (Routine) >
335
+ = head2 trait is default
336
+
337
+ Defined as
338
+
339
+ multi sub trait_mod:<is>(Routine:D $r, :$default!)
340
+
341
+ There is a special trait for C < Routine > s called C < is default > . This trait is
342
+ designed as a way to disambiguate C < multi > calls that would normally throw an
343
+ error because the compiler would not know which one to use. This means that
344
+ given the following two C < Routine > s, the one with the C < is default > trait will
345
+ be called.
346
+
347
+ multi sub f() is default { say "Hello there" }
348
+ multi sub f() { say "Hello friend" }
349
+ f(); # OUTPUT: «"Hello there"»
350
+
351
+ The C < is default > trait can become very useful for debugging and other uses but
352
+ keep in mind that it will only resolve an ambiguous dispatch between two
353
+ C < Routine > s of the same precedence. If one of the C < Routine > s is narrower than
354
+ another, then that one will be called. For example:
355
+
356
+ = begin code
357
+ multi sub f() is default { say "Hello there" }
358
+ multi sub f(:$greet) { say "Hello " ~ $greet }
359
+ f(); # "Use of uninitialized value $greet..."
360
+ = end code
361
+
362
+ In this example, the C < multi > without C < is default > was called because it was
363
+ actually narrower than the C < Sub > with it.
361
364
= end pod
362
365
363
366
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
0 commit comments