@@ -158,16 +158,15 @@ L<CONTROL|https://docs.perl6.org/syntax/CONTROL>.
158
158
CONTROL { .die };
159
159
160
160
= head2 Word quoting: qw
161
- X < |qw word quote > X « |< > word quote »
161
+ X < |qw word quote >
162
162
163
163
= for code :allow<B L>
164
- B « < » a b cB « > » L < eqv > ('a', 'b', 'c')
165
164
B < qw| > ! @ # $ % ^ & * \| < > B < | > eqv '! @ # $ % ^ & * | < >'.words
166
165
B < Q:w { > [ ] \{ \} B < } > eqv ('[', ']', '{', '}')
167
166
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
169
168
"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
171
170
interpolation and escape semantics of the C < q > and single quote string
172
171
delimiters, whereas C < Qw > and C < Q:w > inherit the non-escaping semantics of
173
172
the C < Q > quoter.
@@ -179,13 +178,42 @@ lists of strings. For example, where you could write:
179
178
180
179
It's easier to write and to read this:
181
180
182
- my @directions = < left right up down> ;
181
+ my @directions = qw| left right up down| ;
183
182
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 »
186
185
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) {}
189
217
190
218
= head2 X < Word quoting with quote protection: qww|quote,qww >
191
219
0 commit comments