Skip to content

Commit

Permalink
Clarifies variable name interpolation
Browse files Browse the repository at this point in the history
Using both mechanism: via <> and via ::().
  • Loading branch information
JJ committed Jun 14, 2018
1 parent 450d853 commit 8192aa4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions doc/Language/syntax.pod6
Expand Up @@ -264,26 +264,33 @@ Identifiers can contain colon pairs. The entire colon pair becomes part
of the name of the identifier.
my $foo::bar = 1;
my $foo:bar<2> = 2;
say MY::.keys;
# OUTPUT: «($=pod !UNIT_MARKER EXPORT $_ $! ::?PACKAGE
# GLOBALish $¢ $=finish $/ $foo:bar $foo:bar<2>
# $?PACKAGE)␤»
say OUR::.key; # OUTPUT: «foo␤»
The last sentence shows how the C<foo> package has been created
automatically, as a deposit for variables in that namespace. Colon pairs
in identifiers support interpolation. Please note that resolution of
automatically, as a deposit for variables in that namespace.
Identifiers can also contain single colons, and in that case they can
add I<symbols> within angle brackets. This is a mechanism that supports
interpolation; which is also supported by colonpairs if the interpolated
variable is inserted in parentheses. Please note that resolution of
names often happens at compile time, so interpolation values must be
known at compile time.
my $foo:bar<2> = 2;
constant $c = 42;
my $a:foo<42> = "answer";
say $a:foo«$c»;
# OUTPUT: «answer␤»
Unicode superscript numerals are exponents and not part of an identifier;
e.g. C<$x²> does the square of variable C<$x>. Subscript numerals are TBD.
say $a:foo«$c»; # OUTPUT: «answer␤»
my $buz = "qux";
my $bur::quux = 7;
say $bur::($buz); # OUTPUT: «7␤»
Unicode superscript numerals are exponents and not part of an
identifier; e.g. C<$x²> does the square of variable C<$x>. Subscript
numerals are TBD.
=head2 Term term:<>
Expand Down

0 comments on commit 8192aa4

Please sign in to comment.