Skip to content

Commit 99dea0c

Browse files
committed
Moves is default with the other traits #2824
1 parent 0ad9db1 commit 99dea0c

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

doc/Type/Routine.pod6

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,6 @@ on the C<anon> declarator|/language/variables#The_anon_declarator> for more
2121
information.
2222
2323
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-
5124
=head1 Methods
5225
5326
=head2 method name
@@ -358,6 +331,36 @@ TODO: explain export tags
358331
359332
=end comment
360333
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.
361364
=end pod
362365

363366
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)