@@ -225,34 +225,34 @@ say 'code again';
225
225
226
226
Identifiers are grammatical building blocks that may be used to give a name
227
227
to entities/objects such as constants, variables (e.g. Scalars) and routines
228
- (e.g. Subs and Methods). In a variable name, an identifier is normally preceded
229
- by a sigil; i.e. the sigil is not part of the identifier, only of the variable
230
- name.
228
+ (e.g. Subs and Methods). In a L < variable name|/language/variables > , any sigil
229
+ (and twigil) precedes the identifier and does not form a part thereof.
231
230
232
- constant c = 299792458; # Identifier "c" names an Int
233
- my $a = 123; # Identifier "a" in the name "$a" of a Scalar
234
- sub hello { say "Hello!" }; # Identifier "hello" names a Sub
231
+ constant c = 299792458; # identifier "c" names an Int
232
+ my $a = 123; # identifier "a" in the name "$a" of a Scalar
233
+ sub hello { say "Hello!" }; # identifier "hello" names a Sub
235
234
236
235
Identifiers come in different forms: ordinary identifiers, extended
237
236
identifiers, and compound identifiers.
238
237
239
238
= head3 Ordinary identifiers
240
239
241
240
An ordinary identifier is composed of a leading alphabetic character
242
- that may be followed by one or more alphanumeric characters. It may also
241
+ which may be followed by one or more alphanumeric characters. It may also
243
242
contain isolated, embedded apostrophes C < ' > and/or hyphens C < - > , provided
244
243
that the next character is each time alphabetic.
245
244
246
245
The definitions of "alphabetic" and "alphanumeric" include appropriate Unicode
247
246
characters. Which characters are "appropriate" depends on the implementation.
248
247
In the Rakudo/MoarVM Perl 6 implementation alphabetic characters include
249
- Unicode characters in the character category I < Letter > , and the underscore
250
- C < _ > . Alphanumeric characters additionally include Unicode characters in the
251
- general category I < Number, Decimal Digit > (Nd).
248
+ characters with the Unicode General Category value I < Letter > (L) , and the
249
+ underscore C < _ > . Alphanumeric characters additionally include characters with
250
+ the Unicode General Category value I < Number, Decimal Digit > (Nd).
252
251
253
252
= begin code :skip-test
254
253
# valid ordinary identifiers:
255
254
x
255
+ _snake_oil
256
256
something-longer
257
257
with-numbers1234
258
258
don't-do-that
@@ -265,18 +265,9 @@ piece_of_π
265
265
42 # Identifier does not start with alphabetic character
266
266
with-numbers1234-5 # Embedded hyphen not followed by alphabetic character
267
267
is-prime? # Question mark is not alphanumeric
268
- x² # Superscript 2 has Unicode general category No
268
+ x² # Superscript 2 is not alphanumeric (in the sense explained above)
269
269
= end code
270
270
271
- In the C < x² > example above, since the Unicode superscript numeral C < ² > is not
272
- alphanumeric, it cannot be a part of an ordinary identifier. Still, it may form
273
- part of a valid expression as an operator. The expression C < $x² > , for instance,
274
- produces the square of variable C < $x > . This should be somewhat surprising at this
275
- point, since operators are L < Subs|/type/Sub > , and, as mentioned above, Subs are
276
- named using identifiers. So how does the superscript numeral get accepted as
277
- (part of) an identifier? The key to this riddle lies in the concept of I < extended
278
- identifiers > , which is elaborated upon in the next section.
279
-
280
271
= head3 Extended identifiers
281
272
282
273
It is often convenient to have names that contain characters that are not allowed
@@ -298,26 +289,26 @@ my Dog $spot .= new("woof"); # this.
298
289
= end code
299
290
300
291
Similarly, sets of operators work together in various syntactic categories with names
301
- like C < prefix > , C < infix > , C < postfix > , etc. The long, official names of these operators,
302
- however, often contain characters that are excluded from ordinary identifiers:
292
+ like C < prefix > , C < infix > , C < postfix > , etc. The long, official names of these operators
293
+ often contain characters that are excluded from ordinary identifiers:
303
294
304
295
infix:<+> # the official name of the operator in $a + $b
305
296
infix:<*> # the official name of the operator in $a * $b
306
297
infix:«<=» # the official name of the operator in $a <= $b
307
298
308
- For all such uses, you can append one or more subscript-like adverbial forms or "colon
309
- pairs" to an ordinary identifier to create a so-called I < extended identifier > . When
310
- appended to an identifier (that is, in postfix position), the adverbial syntax
311
- generates unique variants of that identifier.
299
+ For all such uses, you can append one or more "colon pairs" to an ordinary identifier
300
+ to create a so-called I < extended identifier > . When appended to an identifier (that is,
301
+ in postfix position), the colon pair generates unique variants of that identifier.
312
302
313
- The generic colon pair notation acceptable in identifiers is C < :key<value> > : it starts
314
- with a single colon C < : > , followed by an ordinary identifier C < key > , in turn followed
315
- by some quoting bracketing construct, such as C « < > » , C < « » > or C < [' '] > , which quotes
316
- one or more arbitrary characters C < value > :
303
+ The generic colon pair syntax acceptable in identifiers is C < :key<value> > , wherein
304
+ C < key > I < or > C < value > is optional. A colon pair thus starts with a single colon C < : > ,
305
+ followed by an ordinary identifier C < key > and/or a quoting bracketing construct
306
+ such as C « < > » , C < « » > or C < [' '] > which quotes one or more arbitrary characters
307
+ C < value > :
317
308
318
309
= begin code :skip-test
319
310
# exemplary valid extended identifiers:
320
- postfix:<²> # The official long name of the operator in $x²
311
+ postfix:<²> # the official long name of the operator in $x²
321
312
WOW:That'sAwesome
322
313
WOW:That's<<🆒>>
323
314
party:sweet<16>
@@ -326,13 +317,10 @@ party:sweet<16>
326
317
party:16<sweet> # 16 is not an ordinary identifier
327
318
party:16sweet
328
319
party:!a # ...and neither is !a
329
- party:$a # ...or $a
320
+ party:$a # ...nor $a
330
321
= end code
331
- N < As the examples illustrate, the C < key > I < or > the quoted C < value > is optional.
332
- Colon pairs with a null key are normally used for naming operators, as
333
- in the first two examples above. Starting with Perl 6 language version 6.d, colon
334
- pairs with C < sym > as the C < key > (e.g. C « :sym<foo> » ) are reserved for possible
335
- future use. >
322
+ N < Starting with Perl 6 language version 6.d, colon pairs with C < sym > as the
323
+ C < key > (e.g. C « :sym<foo> » ) are reserved for possible future use.>
336
324
337
325
In an extended identifier, the colon pair is considered an integral part of the name,
338
326
so C < infix:<+> > and C < infix:<-> > are two different operators. The bracketing
@@ -384,19 +372,15 @@ names.
384
372
constant $what = 'are';
385
373
my @we:<are>= <the champions>;
386
374
say @we:«$what»; # OUTPUT: «[the champions]»
387
- say @we:[$what]; # OUTPUT: «[the champions]»
388
375
say @we:<$what>; # Compilation error: Variable '@we:<$what>' is not declared
389
376
390
377
= head3 Compound identifiers
391
378
392
379
A compound identifier is an identifier that is composed of two or more
393
380
ordinary and/or extended identifiers that are separated from one another by a
394
- double colon C < :: > . Note that the C < :: > is referred to as a I < double colon > ,
395
- and not as a I < colon pair > . The latter term refers to the adverbial syntax
396
- C < :key<value> > that may be used to create a Pair, or, as described above, to
397
- create an extended identifier.
381
+ double colon C < :: > .
398
382
399
- The double colon C < :: > is also known as the I < namespace separator > or the
383
+ The double colon C < :: > is known as the I < namespace separator > or the
400
384
I < package delimiter > , which clarifies its semantic function in a name: to force
401
385
the preceding portion of the name to be considered a
402
386
L < package|/language/packages > /namespace through which the subsequent portion of
0 commit comments