Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Restructures the traits page
With a better definition given by @moritz Also restructures. Refs #1957
  • Loading branch information
JJ committed Jun 9, 2018
1 parent 71d8675 commit 39fe1e4
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions doc/Language/traits.pod6
Expand Up @@ -4,15 +4,15 @@
=SUBTITLE Compile-time specification of behavior made easy.
In general, L<traits|https://en.wikipedia.org/wiki/Trait_(computer_programming)>
are used to change the behavior of a class, by mixing in attributes and methods
or changing the implementation. That kind of concept is implemented in Perl 6
via L<roles|/language/glossary#Roles>; in this context, Perl 6 calls I<traits>
specifically those that change the internal representation of the class or type.
In Perl 6, I<traits> are compiler hooks attached to objects and classes that
modify their default behavior, functionality or representation. As such compiler
hooks, they are defined in compile time, although they can be used in runtime.
=head1 The X<C<is> trait|is (trait)>
Traits are used extensively in L<native calls|/language/nativecall> to
L<specify the
representation|/language/nativecall#Specifying_the_native_representation> of the
L<specify the representation|/language/nativecall#Specifying_the_native_representation>
of the
data structures that are going to be handled by the native functions via the
C<is repr> suffix; at the same time, C<is native> is used for the routines that
are actually implemented via native functions. These are the representations
Expand Down Expand Up @@ -67,13 +67,16 @@ methods, as above. However, trying to instantiate them this way: C<my
$do-instantiate = don't-instantiate.new;> will yield the error C<You
cannot create an instance of this type (don't-instantiate)>.
=head2 Traits and routines
=head3 C<is> on routines
Traits can be added to the definition of methods and routines to
The C<is> trait can be used on the definition of methods and routines to
establish L<precedence|/functions#Precedence> and
L<associativity|/language/functions#Associativity>. They act as a L<sub
defined using C<trait_mod>|/type/Sub#Traits> which take as argument the
types and names of the traits that are going to be added.
L<associativity|/language/functions#Associativity>. They act as a L<sub defined
using C<trait_mod>|/type/Sub#Traits> which take as argument the types and names
of the traits that are going to be added. In the case of subroutines, traits
would be a way of adding functionality which cuts accross class and role
hierarchies, or can even be used to add behaviors to independently defined
routines.
=end pod

Expand Down

0 comments on commit 39fe1e4

Please sign in to comment.