Skip to content

Commit 8192aa4

Browse files
committed
Clarifies variable name interpolation
Using both mechanism: via <> and via ::().
1 parent 450d853 commit 8192aa4

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

doc/Language/syntax.pod6

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,26 +264,33 @@ Identifiers can contain colon pairs. The entire colon pair becomes part
264264
of the name of the identifier.
265265
266266
my $foo::bar = 1;
267-
my $foo:bar<2> = 2;
268267
say MY::.keys;
269268
# OUTPUT: «($=pod !UNIT_MARKER EXPORT $_ $! ::?PACKAGE
270269
# GLOBALish $¢ $=finish $/ $foo:bar $foo:bar<2>
271270
# $?PACKAGE)␤»
272271
say OUR::.key; # OUTPUT: «foo␤»
273272
274273
The last sentence shows how the C<foo> package has been created
275-
automatically, as a deposit for variables in that namespace. Colon pairs
276-
in identifiers support interpolation. Please note that resolution of
274+
automatically, as a deposit for variables in that namespace.
275+
276+
Identifiers can also contain single colons, and in that case they can
277+
add I<symbols> within angle brackets. This is a mechanism that supports
278+
interpolation; which is also supported by colonpairs if the interpolated
279+
variable is inserted in parentheses. Please note that resolution of
277280
names often happens at compile time, so interpolation values must be
278281
known at compile time.
279282
283+
my $foo:bar<2> = 2;
280284
constant $c = 42;
281285
my $a:foo<42> = "answer";
282-
say $a:foo«$c»;
283-
# OUTPUT: «answer␤»
284-
285-
Unicode superscript numerals are exponents and not part of an identifier;
286-
e.g. C<$x²> does the square of variable C<$x>. Subscript numerals are TBD.
286+
say $a:foo«$c»; # OUTPUT: «answer␤»
287+
my $buz = "qux";
288+
my $bur::quux = 7;
289+
say $bur::($buz); # OUTPUT: «7␤»
290+
291+
Unicode superscript numerals are exponents and not part of an
292+
identifier; e.g. C<$x²> does the square of variable C<$x>. Subscript
293+
numerals are TBD.
287294
288295
=head2 Term term:<>
289296

0 commit comments

Comments
 (0)