Skip to content

Commit fb1820d

Browse files
Further amendments
1 parent 6150f77 commit fb1820d

File tree

1 file changed

+27
-43
lines changed

1 file changed

+27
-43
lines changed

doc/Language/syntax.pod6

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -225,34 +225,34 @@ say 'code again';
225225
226226
Identifiers are grammatical building blocks that may be used to give a name
227227
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.
231230
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
235234
236235
Identifiers come in different forms: ordinary identifiers, extended
237236
identifiers, and compound identifiers.
238237
239238
=head3 Ordinary identifiers
240239
241240
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
243242
contain isolated, embedded apostrophes C<'> and/or hyphens C<->, provided
244243
that the next character is each time alphabetic.
245244
246245
The definitions of "alphabetic" and "alphanumeric" include appropriate Unicode
247246
characters. Which characters are "appropriate" depends on the implementation.
248247
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).
252251
253252
=begin code :skip-test
254253
# valid ordinary identifiers:
255254
x
255+
_snake_oil
256256
something-longer
257257
with-numbers1234
258258
don't-do-that
@@ -265,18 +265,9 @@ piece_of_π
265265
42 # Identifier does not start with alphabetic character
266266
with-numbers1234-5 # Embedded hyphen not followed by alphabetic character
267267
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)
269269
=end code
270270
271-
In the C<> 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-
280271
=head3 Extended identifiers
281272
282273
It is often convenient to have names that contain characters that are not allowed
@@ -298,26 +289,26 @@ my Dog $spot .= new("woof"); # this.
298289
=end code
299290
300291
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:
303294
304295
infix:<+> # the official name of the operator in $a + $b
305296
infix:<*> # the official name of the operator in $a * $b
306297
infix:«<=» # the official name of the operator in $a <= $b
307298
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.
312302
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>:
317308
318309
=begin code :skip-test
319310
# 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²
321312
WOW:That'sAwesome
322313
WOW:That's<<🆒>>
323314
party:sweet<16>
@@ -326,13 +317,10 @@ party:sweet<16>
326317
party:16<sweet> # 16 is not an ordinary identifier
327318
party:16sweet
328319
party:!a # ...and neither is !a
329-
party:$a # ...or $a
320+
party:$a # ...nor $a
330321
=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.>
336324
337325
In an extended identifier, the colon pair is considered an integral part of the name,
338326
so C<infix:<+>> and C<infix:<->> are two different operators. The bracketing
@@ -384,19 +372,15 @@ names.
384372
constant $what = 'are';
385373
my @we:<are>= <the champions>;
386374
say @we:«$what»; # OUTPUT: «[the champions]␤»
387-
say @we:[$what]; # OUTPUT: «[the champions]␤»
388375
say @we:<$what>; # Compilation error: Variable '@we:<$what>' is not declared
389376
390377
=head3 Compound identifiers
391378
392379
A compound identifier is an identifier that is composed of two or more
393380
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<::>.
398382
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
400384
I<package delimiter>, which clarifies its semantic function in a name: to force
401385
the preceding portion of the name to be considered a
402386
L<package|/language/packages>/namespace through which the subsequent portion of

0 commit comments

Comments
 (0)