Author: lwall
Date: 2009-11-20 09:39:12 +0100 (Fri, 20 Nov 2009)
New Revision: 29144
Modified:
docs/Perl6/Spec/S02-bits.pod
docs/Perl6/Spec/S03-operators.pod
docs/Perl6/Spec/S04-control.pod
Log:
[Specs] more constant cleanups
add 'anon' declarator in place of 'my'/'our' misuse
Modified: docs/Perl6/Spec/S02-bits.pod
===================================================================
--- docs/Perl6/Spec/S02-bits.pod 2009-11-20 07:10:40 UTC (rev 29143)
+++ docs/Perl6/Spec/S02-bits.pod 2009-11-20 08:39:12 UTC (rev 29144)
@@ -1492,14 +1492,11 @@
$lay = sub of Egg {...}; # of type
$lay = sub (--> Egg) {...}; # of type
-but you can use a scope modifier to introduce an C<of> prefix type:
+but you can use the C<anon> scope declarator to introduce an C<of> prefix type:
- $lay = my Egg sub {...}; # of type
- $hat = my Rabbit sub {...}; # of type
+ $lay = anon Egg sub {...}; # of type
+ $hat = anon Rabbit sub {...}; # of type
-Because they are anonymous, you can change the C<my> modifier to C<our>
-without affecting the meaning.
-
The return type may also be specified after a C<< --> >> token within
the signature. This doesn't mean exactly the same thing as C<as>.
The C<of> type is the "official" return type, and may therefore be
Modified: docs/Perl6/Spec/S03-operators.pod
===================================================================
--- docs/Perl6/Spec/S03-operators.pod 2009-11-20 07:10:40 UTC (rev 29143)
+++ docs/Perl6/Spec/S03-operators.pod 2009-11-20 08:39:12 UTC (rev 29144)
@@ -16,7 +16,7 @@
Created: 8 Mar 2004
Last Modified: 19 Nov 2009
- Version: 177
+ Version: 178
=head1 Overview
@@ -4273,7 +4273,6 @@
our $foo # lexically scoped alias to package variable
has $foo # object attribute
state $foo # persistent lexical (cloned with closures)
- constant $foo # "our" scoped compile-time constant
Variable declarators such as C<my> now take a I<signature> as their
argument. (The syntax of function signatures is described more fully in S06.)
@@ -4282,11 +4281,20 @@
simple declaration that declares a single variable, along with its
associated type, traits and the initializer:
- constant Dog $foo is woof = 123; # okay: initializes $foo to 123
- constant (Dog $foo is woof = 123); # same thing (with explicit parens)
- constant :(Dog $foo is woof = 123); # same thing (full Signature form)
- constant (Dog $foo is woof) = 123; # wrong: constants cannot be assigned
to
+ my Dog $foo is woof = 123; # okay: initializes $foo to 123
+ my (Dog $foo is woof = 123); # same thing (with explicit parens)
+ my :(Dog $foo is woof = 123); # same thing (full Signature form)
+The C<constant> declarator can declare either variables or names
+as compile-time constants:
+
+ constant $foo = 1; # compile-time constant variable
+ constant bar = 2; # compile-time constant symbol
+
+Because it can declare names in "type" space, the C<constant>
+declarator may not declare using the signature, which would be
+ambiguous.
+
Each declarator can take an initializer following an equals
sign (which should not be confused with a normal assignment, because
the timing of the initialization depends on the natural lifetime of the
@@ -4315,17 +4323,17 @@
List-context pseudo-assignment is supported for simple declarations but
not for signature defaults:
- constant @foo = 1,2,3; # okay: initializes @foo to (1,2,3)
- constant (@foo = 1,2,3); # wrong: 2 and 3 are not variable names
+ my @foo = 1,2,3; # okay: initializes @foo to (1,2,3)
+ my (@foo = 1,2,3); # wrong: 2 and 3 are not variable names
When parentheses are omitted, you may use any infix assignment operator
instead of C<=> as the initializer. In that case, the left hand side of
the infix operator will be the variable's prototype object:
- constant Dog $fido .= new; # okay: a constant Dog object
- constant Dog $fido = Dog.new; # same thing
- constant Dog $fido = $fido.new; # wrong: invalid self-reference
- constant (Dog $fido .= new); # wrong: cannot use .= with parens
+ my Dog $fido .= new; # okay: a constant Dog object
+ my Dog $fido = Dog.new; # same thing
+ my Dog $fido = $fido.new; # wrong: invalid self-reference
+ my (Dog $fido .= new); # wrong: cannot use .= inside signature
Note that very few mutating operators make sense on a type object, however,
since type objects are a kind of undefined object. (Those operators with
@@ -4396,6 +4404,8 @@
class Foo
role Foo
subset Foo
+ enum Foo
+ constant Foo
and code declarators:
@@ -4412,6 +4422,17 @@
These all have their uses and are explained in subsequent Synopses.
+Note that since C<constant> is parsed as a type declarator (essentially
+declaring a type with a single value), it can actually take a scope
+declarator in front:
+
+ my constant companion = 'Fido';
+ has constant $.pi = 22/7;
+ state constant $latch = snapshot();
+
+In these cases the explicit scoping determines when the initializer is
+evaluated.
+
=head1 Argument List Interpolating
Perl 5 forced interpolation of a function's argument list by use of
Modified: docs/Perl6/Spec/S04-control.pod
===================================================================
--- docs/Perl6/Spec/S04-control.pod 2009-11-20 07:10:40 UTC (rev 29143)
+++ docs/Perl6/Spec/S04-control.pod 2009-11-20 08:39:12 UTC (rev 29144)
@@ -157,14 +157,16 @@
As in Perl 5, "C<our $foo>" introduces a lexically scoped alias for
a variable in the current package.
-The new C<constant> declarator introduces an "our"-scoped name
-for a compile-time constant, either a variable or named value, which
+The new C<constant> declarator introduces a
+compile-time constant, either a variable or named value, which
may be initialized with a pseudo-assignment:
constant Num $pi = 3;
constant Num π = atan2(2,2) * 4;
-The initializing expression is evaluated at C<BEGIN> time.
+The initializing expression is evaluated at C<BEGIN> time. Constants
+(and enums) default to C<our> scoping so they can be accessed from
+outside the package.
There is a new C<state> declarator that introduces a lexically scoped
variable like C<my> does, but with a lifetime that persists for the