Skip to content

Commit

Permalink
Expands confusing name lookup examples
Browse files Browse the repository at this point in the history
And fixes some of them. Closes #969
  • Loading branch information
JJ committed May 31, 2018
1 parent e9de327 commit 546102f
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions doc/Language/packages.pod6
Expand Up @@ -22,28 +22,40 @@ with a longer name to disambiguate.
A I<name> is anything that is a legal part of a variable name (not counting the
sigil). This includes:
=for code :skip-test
$foo # simple identifiers
$Foo::Bar::baz # compound identifiers separated by ::
$Foo::($bar)::baz # compound identifiers that perform interpolations
$42 # numeric names
$! # certain punctuation variables
=for code
class Foo {
sub zape () { say "zipi" }
class Bar {
method baz () { return 'Þor is mighty' }
our &zape = { "zipi" };
our $quux = 42;
}
}
my $foo; # simple identifiers
say Foo::Bar.baz; # Calling a method; OUTPUT: «Þor is mighty␤»
say $Foo::Bar::zape; # compound identifiers separated by ::; OUTPUT: «zipi␤»
my $bar = 'Bar';
say $Foo::($bar)::quux; # compound identifiers with interpolations; OUTPUT: «42␤»
$42; # numeric names
$!; # certain punctuation variables
X<|::,package>
C<::> is used to separate nested package names.
=head2 Package-qualified names
Ordinary package-qualified names look like:
$Foo::Bar::baz # the $baz variable in package Foo::Bar
Ordinary package-qualified names look like; C<$Foo::Bar::quux> would be the
C<$quux> variable in package C<Foo::Bar>; C<Foo::Bar::zape> would represent the
C<&zape> variable in the same package.
Sometimes it's clearer to keep the sigil with the variable name, so an
alternate way to write this is:
Foo::Bar::<$baz>
Foo::Bar::<$quux>
This is resolved at compile time because the variable name is a constant.
(This does not work with the C<&zape> variable) The name is resolved at compile
time because the variable name is a constant.
If the name part before C<::> is null, it means the package is unspecified and
must be searched for. Generally this means that an initial C<::> following the
Expand Down

0 comments on commit 546102f

Please sign in to comment.