File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,26 @@ starting string:
279
279
say join ", ", ("az", *.succ ... "bc")
280
280
az, ba, bb, bc
281
281
282
+ The smart match operator C < ~~ > does set the topic C < $_ > to its LHS. In
283
+ conjunction with implicit method call on the topic this can lead to surprising
284
+ results.
285
+
286
+ my &method = { note $_; $_ };
287
+ $_ = 'object';
288
+ say .&method;
289
+ # OUTPUT « objectobject »
290
+ say 'topic' ~~ .&method;
291
+ # OUTPUT « topicTrue »
292
+
293
+ In many cases flipping the method call to the LHS will work.
294
+
295
+ my &method = { note $_; $_ };
296
+ $_ = 'object';
297
+ say .&method;
298
+ # OUTPUT « objectobject »
299
+ say .&method ~~ 'topic';
300
+ # OUTPUT « objectTrue »
301
+
282
302
= head1 Common Precedence Mistakes
283
303
284
304
= head2 Adverbs and Precedence
You can’t perform that action at this time.
0 commit comments