Skip to content

Commit 53ef347

Browse files
committed
show how to call subs that (don't) overload coercers
1 parent ecc15e2 commit 53ef347

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

doc/Type/Sub.pod6

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@
66
77
class Sub is Routine { }
88
9-
A type for subroutines. Subs are created with the C<sub> declarator keyword
9+
A type for subroutines. Subs are created with the C<sub> declarator keyword followed by a identifier.
1010
1111
my $s = sub ($a, $b) { $a + $b };
1212
say $s.WHAT; # (Sub)
1313
say $s(2, 5); # 7
1414
15+
Note that subs that go by the same name as
16+
L<coercers|/language/typesystem#Coercion> will not take precedence over
17+
coercers. To call them use the C<&>-sigil.
18+
19+
sub Int(Str $s){'oi‽'};
20+
say [Int, Int('42'),&Int('42')];
21+
# OUTPUT«[(Int) 42 oi‽]␤»
22+
1523
=head1 Traits
1624
X<|trait_mod (declarator)>
1725

0 commit comments

Comments
 (0)