Skip to content

Commit 03c2f46

Browse files
committed
Add a caveat about tricky precedence on ranges
1 parent ef9708a commit 03c2f46

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

doc/Language/traps.pod

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ There are methods that Str inherits from Any that work on iterables like lists.
227227
say "abc".reverse; # abc (what is wrong)
228228
say "abc".comb.reverse.join; # cba
229229
230-
=head1 Adverbs and Precedence
230+
=head1 Common Precedence Mistakes
231+
232+
=head2 Adverbs and Precedence
231233
232234
Adverbs do have a precedence that may not follow the order of operators that is displayed on your screen. If two operators of equal precedence are followed by an adverb it will pick the first operator it find in the abstract syntax tree. Use paranteses to help Perl 6 to understand what you mean or use operators with looser precedence.
233235
@@ -237,7 +239,14 @@ Adverbs do have a precedence that may not follow the order of operators that is
237239
say !(%x<b>:exists); # works too
238240
say not %x<b>:exists; # works as well
239241
say True unless %x<b>:exists; # avoid negation altogether
240-
242+
243+
=head2 Ranges and Precedence
244+
245+
The loose precedence of C<..> can lead to some errors. It is usually best to parenthesize ranges when you want to operate on the entire range.
246+
247+
1..3.say # says "3" (and warns about useless "..")
248+
(1..3).say # says "1..3"
249+
241250
=end pod
242251

243252
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)