Skip to content

Commit fa0b8f6

Browse files
authored
Differentiate <...> and qw|...|
Fixes RT#130184: https://rt.perl.org/Ticket/Display.html?id=130184
1 parent f94db38 commit fa0b8f6

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

doc/Language/quoting.pod6

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,15 @@ L<CONTROL|https://docs.perl6.org/syntax/CONTROL>.
158158
CONTROL { .die };
159159
160160
=head2 Word quoting: qw
161-
X<|qw word quote>X«|< > word quote»
161+
X<|qw word quote>
162162
163163
=for code :allow<B L>
164-
B«<»a b cB«>» L<eqv> ('a', 'b', 'c')
165164
B<qw|>! @ # $ % ^ & * \| < > B<|> eqv '! @ # $ % ^ & * | < >'.words
166165
B<Q:w {> [ ] \{ \} B<}> eqv ('[', ']', '{', '}')
167166
168-
The C<:w> form, usually written C«<…>» or C<qw>, splits the string into
167+
The C<:w> form, usually written as C<qw>, splits the string into
169168
"words". In this context, words are defined as sequences of non-whitespace
170-
characters separated by whitespace. The C<q:w> and C<qw> forms inherit the
169+
characters separated by whitespace. The C<q:w> and C<qw> forms inherit the
171170
interpolation and escape semantics of the C<q> and single quote string
172171
delimiters, whereas C<Qw> and C<Q:w> inherit the non-escaping semantics of
173172
the C<Q> quoter.
@@ -179,13 +178,42 @@ lists of strings. For example, where you could write:
179178
180179
It's easier to write and to read this:
181180
182-
my @directions = <left right up down>;
181+
my @directions = qw|left right up down|;
183182
184-
Please note that a fraction without any leading or trailing spaces is not a
185-
word quote but a L<Rat|/type/Rat>-literal.
183+
=head2 Word quoting: < >
184+
X«|< > word quote»
186185
187-
<1/2>.WHAT.say;
188-
# OUTPUT«(Rat)␤»
186+
=for code :allow<B L>
187+
B«<»a b cB«>» L<eqv> ('a', 'b', 'c'); # True
188+
B«<»a b 42B«>» L<eqv> ('a', 'b', '42'); # False, the 42 become an IntStr allomorph
189+
say < 42 > ~~ Int; # True
190+
say < 42 > ~~ Str; # Also True
191+
192+
The angle brackets quoting is like C<qw>, but with extra feature that lets you
193+
construct C<allomorphs/language/glossary#index-entry-Allomorph> or literals
194+
of certain numbers:
195+
196+
say <42 4/2 1e6 1+1i abc>.perl;
197+
# OUTPUT«(IntStr.new(42, "42"), RatStr.new(2.0, "4/2"), NumStr.new(1000000e0, "1e6"), ComplexStr.new(<1+1i>, "1+1i"), "abc")␤»
198+
199+
To construct a L«C<Rat>|/type/Rat» or L«C<Complex>|/type/Complex» literal, use angle
200+
brackets around the number, without any extra spaces:
201+
202+
say <42/10>.^name; # Rat
203+
say <1+42i>.^name; # Complex
204+
say < 42/10 >.^name; # RatStr
205+
say < 1+42i >.^name; # ComplexStr
206+
207+
Compared to C<42/10> and C<1+42i>, there's no division (or addition) operation
208+
involved. This is useful for literals in routine signatures, for example:
209+
210+
sub close-enough-τ (<355/113>) {
211+
say "Your π is close enough!"
212+
}
213+
close-enough-τ 710/226; # Your π is close enough!
214+
215+
# WRONG: can't do this, since it's a division operation
216+
sub compilation-failure (355/113) {}
189217
190218
=head2 X<Word quoting with quote protection: qww|quote,qww>
191219

0 commit comments

Comments
 (0)