Skip to content

Commit 39fe1e4

Browse files
committed
Restructures the traits page
With a better definition given by @moritz Also restructures. Refs #1957
1 parent 71d8675 commit 39fe1e4

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

doc/Language/traits.pod6

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
55
=SUBTITLE Compile-time specification of behavior made easy.
66
7-
In general, L<traits|https://en.wikipedia.org/wiki/Trait_(computer_programming)>
8-
are used to change the behavior of a class, by mixing in attributes and methods
9-
or changing the implementation. That kind of concept is implemented in Perl 6
10-
via L<roles|/language/glossary#Roles>; in this context, Perl 6 calls I<traits>
11-
specifically those that change the internal representation of the class or type.
7+
In Perl 6, I<traits> are compiler hooks attached to objects and classes that
8+
modify their default behavior, functionality or representation. As such compiler
9+
hooks, they are defined in compile time, although they can be used in runtime.
10+
11+
=head1 The X<C<is> trait|is (trait)>
1212
1313
Traits are used extensively in L<native calls|/language/nativecall> to
14-
L<specify the
15-
representation|/language/nativecall#Specifying_the_native_representation> of the
14+
L<specify the representation|/language/nativecall#Specifying_the_native_representation>
15+
of the
1616
data structures that are going to be handled by the native functions via the
1717
C<is repr> suffix; at the same time, C<is native> is used for the routines that
1818
are actually implemented via native functions. These are the representations
@@ -67,13 +67,16 @@ methods, as above. However, trying to instantiate them this way: C<my
6767
$do-instantiate = don't-instantiate.new;> will yield the error C<You
6868
cannot create an instance of this type (don't-instantiate)>.
6969
70-
=head2 Traits and routines
70+
=head3 C<is> on routines
7171
72-
Traits can be added to the definition of methods and routines to
72+
The C<is> trait can be used on the definition of methods and routines to
7373
establish L<precedence|/functions#Precedence> and
74-
L<associativity|/language/functions#Associativity>. They act as a L<sub
75-
defined using C<trait_mod>|/type/Sub#Traits> which take as argument the
76-
types and names of the traits that are going to be added.
74+
L<associativity|/language/functions#Associativity>. They act as a L<sub defined
75+
using C<trait_mod>|/type/Sub#Traits> which take as argument the types and names
76+
of the traits that are going to be added. In the case of subroutines, traits
77+
would be a way of adding functionality which cuts accross class and role
78+
hierarchies, or can even be used to add behaviors to independently defined
79+
routines.
7780
7881
=end pod
7982

0 commit comments

Comments
 (0)