Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow use of :: as anonymous package name

Clear up more * as GLOBAL fossils


git-svn-id: http://svn.pugscode.org/pugs@25323 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit 60cc0dba95aacaf49568aa7c86a76074a9b7ee37 1 parent 6ecb2d0
lwall authored
Showing with 46 additions and 31 deletions.
  1. +7 −2 S10-packages.pod
  2. +19 −19 S11-modules.pod
  3. +20 −10 S12-objects.pod
View
9 S10-packages.pod
@@ -12,9 +12,9 @@ Larry Wall <larry@wall.org>
Maintainer: Larry Wall <larry@wall.org>
Date: 27 Oct 2004
- Last Modified: 12 Feb 2009
+ Last Modified: 13 Feb 2009
Number: 10
- Version: 8
+ Version: 9
=head1 Overview
@@ -58,6 +58,11 @@ a global package name.
To declare a lexically scoped package, use C<my package>.
+To declare an anonymous package you can use either of
+
+ package {...}
+ package :: {...}
+
All files start out being parsed in the C<GLOBAL>
package, but may switch to some other package scope depending on the first
package-ish declaration. If that first declaration is not a package variant, then
View
38 S11-modules.pod
@@ -12,9 +12,9 @@ Larry Wall <larry@wall.org>
Maintainer: Larry Wall <larry@wall.org>
Date: 27 Oct 2004
- Last Modified: 06 Jan 2009
+ Last Modified: 13 Feb 2009
Number: 11
- Version: 25
+ Version: 26
=head1 Overview
@@ -46,7 +46,7 @@ imply globalness as it does in Perl 5. (Use C<GLOBAL::> for that.)
A bare (unscoped) C<module> declarator declares a nested C<our> module
name within the current package. However, at the start of the file,
-the current package is C<*>, so the first such declaration in the
+the current package is C<GLOBAL>, so the first such declaration in the
file is automatically global.
You can use C<our module> to explicitly
@@ -56,23 +56,23 @@ Module names are always searched for from innermost scopes to outermost.
As with an initial C<::>, the presence of a C<::> within the name
does not imply globalness (unlike in Perl 5).
-The C<::*> namespace is not "main". The default namespace for the
-main program is C<::*Main>, which it switches to from * as soon as
-it sees the first declaration, if that declaration doesn't set the
-package name. (Putting C<module Main;> at the top of your program
+The default namespace for the main program is C<GLOBAL>.
+(Putting C<module GLOBAL;> at the top of your program
is redundant, except insofar as it tells Perl that the code is Perl
6 code and not Perl 5 code. But it's better to say "use v6" for that.)
-But note that if you say
+Module traits are set using C<is>:
- use v6;
- module Foo {...}
+ module Foo is bar {...}
-you've just created Main::Foo, not *Foo.
+An anonymous module make be created with either of:
-Module traits are set using C<is>:
+ module {...}
+ module :: {...}
- module Foo is bar {...}
+The second form is useful if you need to apply a trait:
+
+ module :: is bar {...}
=head1 Exportation
@@ -133,14 +133,14 @@ Importing via C<use> binds into the current lexical scope by default
You can be explicit about the desired namespace:
- use Sense :MY<common> :OUR<@horse> :GLOBAL<$warming>;
+ use Sense :MY<common> :OUR<@horse> :CONTEXT<$sensitive>;
That's pretty much equivalent to:
use Sense;
- my &common ::= &Sense::common;
- our @horse ::= @Sense::horse;
- $*warming ::= $Sense::warming;
+ my &common ::= Sense::<&common>;
+ our @horse ::= Sense::<@horse>;
+ $*sensitive ::= Sense::<$sensitive>
It is also possible to re-export the imported symbols:
@@ -187,7 +187,7 @@ to the package scope instead:
You may also import symbols from the various pseudo-packages listed in S02.
They behave as if all their symbols are in the C<:ALL> export list:
- use GLOBAL <$IN $OUT $ERR>;
+ use CONTEXT <$IN $OUT $ERR>;
require CALLER <$x $y>;
# Same as:
@@ -195,7 +195,7 @@ They behave as if all their symbols are in the C<:ALL> export list:
# my ($x, $y) := ($CALLER::x, $CALLER::y)
As pseudo-packages are always already preloaded, C<use> and C<require> will
-never attempt to load, for example, C<GLOBAL.pm> from an external source.
+never attempt to load, for example, C<CALLER.pm> from an external source.
=head1 Versioning
View
30 S12-objects.pod
@@ -12,9 +12,9 @@ Larry Wall <larry@wall.org>
Maintainer: Larry Wall <larry@wall.org>
Date: 27 Oct 2004
- Last Modified: 21 Jan 2009
+ Last Modified: 12 Feb 2009
Number: 12
- Version: 68
+ Version: 69
=head1 Overview
@@ -74,10 +74,12 @@ Use composition and/or delegation to change the representation.
Since there are no barewords in Perl 6, bare class names must be
predeclared. You can predeclare a stub class and fill it in later
-just as you would a subroutine. Alternately, you can define a local
-class or type variable using the C<::> type sigil. In an rvalue
-context the C<::> prefix is a no-op, but in a declarational context,
-it binds a new type name within its declared scope.
+just as you would a subroutine.
+
+You can force interpretation of a name as a class or type name using
+the C<::> prefix. In an rvalue context the C<::> prefix is a no-op,
+but in a declarational context, it binds a new type name within the
+declaration's scope along with anything else being declared by the declaration.
Without a C<my> or other scoping declarator, a bare C<class>
declarator declares an C<our> declarator, that is, a name within
@@ -152,6 +154,14 @@ handled with lexical scoping in Perl 6. The fact that importation
is lexical by default also means that any names your class imports
are also private by default.
+In an anonymous class declaration, C<::> by itself may represent the
+anonymous class name if desired:
+
+ class {...} # ok
+ class is Mammal {...} # WRONG
+ class :: is Mammal {...} # ok
+ class { is Mammal; ...} # also ok
+
=head1 Methods
Methods are routines declared in a class with the C<method> keyword:
@@ -1128,7 +1138,7 @@ class composition time. This means that if two roles bring in the
same crony, there's no conflict--it's just as if the class pulled in
the crony role itself and the respective roles didn't. A role may
never conflict with itself regardless of its method of incorporation.
-A role that brings in two conflicting crony roles *may* resolve them
+A role that brings in two conflicting crony roles I<may> resolve them
as if it were a class. This solution is accepted by the class unless
the class supplies its own solution. If two different roles resolve
the same crony conflict two different ways, those roles are themselves
@@ -1428,11 +1438,11 @@ These capture control if C<MyBase> wants to capture control of how it gets
used by any class or container. But usually you can just let it call
the generic defaults:
- multi *trait_auxiliary:is(Class $base, Class $class; $arg?) {...}
+ multi trait_auxiliary:is(Class $base, Class $class; $arg?) {...}
which adds C<$base> to the "isa" list of C<$class>, or
- multi *trait_auxiliary:is(Class $tied, Any $container; $arg?) {...}
+ multi trait_auxiliary:is(Class $tied, Any $container; $arg?) {...}
which sets the "tie" type of the container to the implementation type
in C<$tied>.
@@ -1443,7 +1453,7 @@ or "C<should>", or "C<does>". We call these helping verbs "trait
auxiliaries". Here's "C<will>", which (being syntactic sugar) merely
delegates to back to "is":
- multi sub *trait_auxiliary:will($trait, $container; &arg) {
+ multi sub trait_auxiliary:will($trait, $container; &arg) {
trait_auxiliary:is($trait, $container, &arg);
}
Please sign in to comment.
Something went wrong with that request. Please try again.