Skip to content

Commit

Permalink
Moves example from traps to objects
Browse files Browse the repository at this point in the history
Since a warning is issued right now, it's not a trap; but some
clarification is needed about precedence of the `but` operator. This
closes #1950 and closes #1953, which was changed before.
  • Loading branch information
JJ committed Apr 23, 2018
1 parent f93418d commit f14b8a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 13 additions & 0 deletions doc/Language/objects.pod6
Expand Up @@ -966,6 +966,19 @@ container. Thus, @-sigiled containers will require binding to make the role
stick. Some operators will return a new value, which effectively strips
the mixin from the result.
The operator infix:<but> is narrower than the list constructor. When providing
a list of roles to mix in, always use parentheses.
=for code
role R1 { method m {} }
role R2 { method n {} }
my $a = 1 but R1,R2; # R2 is in sink context, issues a WARNING
say $a.^name;
# OUTPUT: «Int+{R1}␤»
my $all-roles = 1 but (R1,R2);
say $all-roles.^name; # OUTPUT: «Int+{R1,R2}␤»
Mixins can be used at any point in your object's life.
# A counter for Table of Contents
Expand Down
12 changes: 0 additions & 12 deletions doc/Language/traps.pod6
Expand Up @@ -836,18 +836,6 @@ to a power, use parentheses:
say (-1)²; # OUTPUT: «1␤»
say (-1)**2; # OUTPUT: «1␤»
=head2 C<but> in List Construction
The operator infix:<but> is narrower than the list constructor. When providing
a list of roles to mix in, always use parentheses.
=for code
role R1 { method m {} }
role R2 { method n {} }
my $a = 1 but R1,R2; # R2 is in sink context
say $a.^name;
# OUTPUT: «Int+{R1}␤»
=head1 Subroutine and method calls
Subroutine and method calls can be made using one of two forms:
Expand Down

0 comments on commit f14b8a2

Please sign in to comment.