@@ -229,9 +229,9 @@ to entities/objects such as constants, variables (e.g. Scalars) and routines
229
229
(e.g. Subs and Methods). In a L < variable name|/language/variables > , any sigil
230
230
(and twigil) precedes the identifier and does not form a part thereof.
231
231
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
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
235
235
236
236
Identifiers come in different forms: ordinary identifiers, extended
237
237
identifiers, and compound identifiers.
@@ -266,7 +266,7 @@ piece_of_π
266
266
42 # identifier does not start with alphabetic character
267
267
with-numbers1234-5 # embedded hyphen not followed by alphabetic character
268
268
is-prime? # question mark is not alphanumeric
269
- x² # superscript 2 is not alphanumeric (in the sense explained above)
269
+ x² # superscript 2 is not alphanumeric (explained above)
270
270
= end code
271
271
272
272
= head3 Extended identifiers
@@ -278,14 +278,13 @@ to be identifiable individually. For example, you might use a module whose short
278
278
name is C < Dog > , while its long name includes its naming authority and version:
279
279
280
280
= begin code :skip-test<identifiers only>
281
- Dog:auth<Somebody>:ver<1.0> # long module names including author and version
281
+ Dog:auth<Somebody>:ver<1.0> # long module names including author and version
282
282
Dog:auth<Somebody>:ver<2.0>
283
283
284
284
use Dog:auth<Somebody>:ver<2.0>;
285
-
286
- # Selection of second module causes its full name to be aliased to the short
287
- # name for the rest of # the lexical scope, allowing a declaration like
288
- # this.
285
+ # Selection of second module causes its full name to be aliased to the
286
+ # short name for the rest of # the lexical scope, allowing a declaration
287
+ # like this.
289
288
my Dog $spot .= new("woof");
290
289
= end code
291
290
@@ -296,9 +295,9 @@ The long name is what constitutes the extended identifier, and includes this
296
295
syntactic category; the short name will be included in quotes in the definition:
297
296
298
297
= begin code :skip-test<identifiers only>
299
- infix:<+> # the official name of the operator in $a + $b
300
- infix:<*> # the official name of the operator in $a * $b
301
- infix:«<=» # the official name of the operator in $a <= $b
298
+ infix:<+> # the official name of the operator in $a + $b
299
+ infix:<*> # the official name of the operator in $a * $b
300
+ infix:«<=» # the official name of the operator in $a <= $b
302
301
= end code
303
302
304
303
For all such uses, you can append one or more colon-separated string to an
@@ -313,16 +312,16 @@ or C<[' ']> which quotes one or more arbitrary characters C<value>:
313
312
314
313
= begin code :skip-test<Identifiers good and bad>
315
314
# exemplary valid extended identifiers:
316
- postfix:<²> # the official long name of the operator in $x²
315
+ postfix:<²> # the official long name of the operator in $x²
317
316
WOW:That'sAwesome
318
317
WOW:That's<<🆒>>
319
318
party:sweet<16>
320
319
321
320
# exemplary invalid extended identifiers:
322
- party:16<sweet> # 16 is not an ordinary identifier
321
+ party:16<sweet> # 16 is not an ordinary identifier
323
322
party:16sweet
324
- party:!a # ...and neither is !a
325
- party:$a # ...nor $a
323
+ party:!a # ...and neither is !a
324
+ party:$a # ...nor $a
326
325
= end code
327
326
N < Starting with Perl 6 language version 6.d, colon pairs with C < sym > as the
328
327
C < key > (e.g. C « :sym<foo> » ) are reserved for possible future use.>
@@ -345,8 +344,8 @@ Similarly, all of this works:
345
344
= begin code
346
345
my $foo:bar<baz> = 'quux';
347
346
say $foo:bar«baz»; # OUTPUT: «quux»
348
- my $take-me:<home> = 'When the glory has no end';
349
- say $take-me:['home']; # OUTPUT: «When the [...]»
347
+ my $take-me:<home> = 'Where the glory has no end';
348
+ say $take-me:['home']; # OUTPUT: «Where [...]»
350
349
my $foo:bar<2> = 5;
351
350
say $foo:bar(1+1); # OUTPUT: «5»
352
351
= end code
@@ -355,9 +354,9 @@ Where an extended identifier comprises two or more colon pairs, their order
355
354
is generally significant:
356
355
357
356
= begin code
358
- my $a:b<c>:d<e> = 100;
359
- my $a:d<e>:b<c> = 200;
360
- say $a:b<c>:d<e>; # OUTPUT: «100», NOT: «200»
357
+ my $a:b<c>:d<e> = 100;
358
+ my $a:d<e>:b<c> = 200;
359
+ say $a:b<c>:d<e>; # OUTPUT: «100», NOT: «200»
361
360
= end code
362
361
363
362
An exception to this rule is I < module versioning > ; so these identifiers
@@ -373,9 +372,9 @@ requires the use of L<constants|/language/terms#Constants> for the interpolation
373
372
values:
374
373
375
374
= begin code
376
- constant $c = 42; # Constant binds to Int; $-sigil enables interpolation
375
+ constant $c = 42; # Constant binds to Int; $-sigil enables interpolation
377
376
my $a:foo<42> = "answer";
378
- say $a:foo«$c»; # OUTPUT: «answer»
377
+ say $a:foo«$c»; # OUTPUT: «answer»
379
378
= end code
380
379
381
380
Although quoting bracketing constructs are generally interchangeable
@@ -388,7 +387,8 @@ names.
388
387
constant $what = 'are';
389
388
my @we:<are>= <the champions>;
390
389
say @we:«$what»; # OUTPUT: «[the champions]»
391
- say @we:<$what>; # Compilation error: Variable '@we:<$what>' is not declared
390
+ say @we:<$what>;
391
+ # Compilation error: Variable '@we:<$what>' is not declared
392
392
= end code
393
393
394
394
= head3 Compound identifiers
@@ -419,8 +419,8 @@ packages:
419
419
420
420
= begin code
421
421
my $foo::bar = 1;
422
- say OUR::.keys; # OUTPUT: «(foo)»
423
- say OUR::foo.HOW # OUTPUT: «Perl6::Metamodel::PackageHOW.new»
422
+ say OUR::.keys; # OUTPUT: «(foo)»
423
+ say OUR::foo.HOW # OUTPUT: «Perl6::Metamodel::PackageHOW.new»
424
424
= end code
425
425
426
426
The last lines shows how the C < foo > package was created automatically, as a
@@ -595,13 +595,14 @@ number:
595
595
Integers default to signed base-10, but you can use other bases. For details,
596
596
see L < Int|/type/Int > .
597
597
598
- = begin code :skip-test
599
- -2 # actually not a literal, but unary - operator applied to numeric literal 2
600
- 12345
601
- 0xBEEF # base 16
602
- 0o755 # base 8
603
- :3<1201> # arbitrary base, here base 3
604
- = end code
598
+ = begin code :skip-test
599
+ # actually not a literal, but unary - operator applied to numeric literal 2
600
+ -2
601
+ 12345
602
+ 0xBEEF # base 16
603
+ 0o755 # base 8
604
+ :3<1201> # arbitrary base, here base 3
605
+ = end code
605
606
606
607
= head4 Rat literals
607
608
0 commit comments