Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
doc trap of ~~ in conjunction with .method-name
  • Loading branch information
gfldex committed Sep 29, 2016
1 parent 05c700e commit 41a7f6e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/Language/traps.pod6
Expand Up @@ -279,6 +279,26 @@ starting string:
say join ", ", ("az", *.succ ... "bc")
az, ba, bb, bc
The smart match operator C<~~> does set the topic C<$_> to its LHS. In
conjunction with implicit method call on the topic this can lead to surprising
results.
my &method = { note $_; $_ };
$_ = 'object';
say .&method;
# OUTPUT«object␤object␤»
say 'topic' ~~ .&method;
# OUTPUT«topic␤True␤»
In many cases flipping the method call to the LHS will work.
my &method = { note $_; $_ };
$_ = 'object';
say .&method;
# OUTPUT«object␤object␤»
say .&method ~~ 'topic';
# OUTPUT«object␤True␤»
=head1 Common Precedence Mistakes
=head2 Adverbs and Precedence
Expand Down

0 comments on commit 41a7f6e

Please sign in to comment.