Re: Is it 'anon role' but not 'anon enum'? (Re: r29250 - in docs/Perl6/Spec: . S32-setting-library)

2010-01-09 Thread Larry Wall
On Sat, Jan 09, 2010 at 12:51:42AM +0100, Carl Mäsak wrote:
: pugscommitbot, channeling Larry (>):
: > [...]
: > +    $x = "Today" but Tue;       # $x.Day is read-only
: > +    $x = "Today" but Day;       # $x.Day is read-write
: > +
: > +Mixing in a specific enum object implies only the readonly accessor.
: > +
: >     $x = "Today" but Tue;
: >
: > -really means something more like:
: > +really means something like:
: >
: > -    $x = "Today";
: > -    $x does Has[Day, '$.Day', (:rw), { Tue }];
: > +    $x = "Today".clone;
: > +    $x does anon role { method Day { Day::Tue } };
: > [...]
: 
: I'm not 100% clear on when this 'anon' keyword is to be applied and when not.

Syntactically, it is allowed anywhere 'my' is allowed.

: Why is it 'anon role' for anonymous roles but not 'anon enum' for
: anonymous enumerations?

The enum and constant declarators used to be parsed more like 'my',
but they have recently moved in the direction of filling the type
declarator slot, independent of scoping declarators such as 'my'.
(The subset declarator now also relies on * to parse any 'of'
instead of special casing it, so that it can also detect an extra
'of' type using the same validator.)  Anyway, that transition was not
complete, so I had to patch up STD a bit yesterday.  Hopefully the
type-like declarators are more consistent now.

: If 'anon' isn't strictly required before 'enum', is it still allowed?

Yes, it is optional, and should work everywhere 'my' does now.

As a declarator, 'anon' has several effects.  Syntactically, it allows you
to put an 'of' type before any non-scope_declarator that wants an 'of'
type, including enum, constant, subset, sub, multi, etc.

my $x = anon Int subset Even where * !% 2;
my $y = anon Sink sub log($x) { say $*LOG: $x };
my $z = anon uint2 enum ;

(Arguably, some of these would be more readable with an explicit 'of'
or 'returns' trait, but we like to keep the possibilities open.)

Since you can optionally give a name for most declarators, the 'anon'
declarator also has the effect of throwing away the name if you happen
to have supplied one:

my $foo = anon role Foo {...};

So the anonymous role thinks its name is 'Foo', but that name is not
put into any symbol table.

And finally, while you can say something like:

my $x = role {...}

it may be better self-documentation to say:

my $x = anon role {...}

just to tell the reader that the omission of the name was intentional,
or to make the semantic nature of the beastie more clear up front, if
the other form makes you do mental backtracking.

Larry


Is it 'anon role' but not 'anon enum'? (Re: r29250 - in docs/Perl6/Spec: . S32-setting-library)

2010-01-08 Thread Carl Mäsak
pugscommitbot, channeling Larry (>):
> [...]
> +    $x = "Today" but Tue;       # $x.Day is read-only
> +    $x = "Today" but Day;       # $x.Day is read-write
> +
> +Mixing in a specific enum object implies only the readonly accessor.
> +
>     $x = "Today" but Tue;
>
> -really means something more like:
> +really means something like:
>
> -    $x = "Today";
> -    $x does Has[Day, '$.Day', (:rw), { Tue }];
> +    $x = "Today".clone;
> +    $x does anon role { method Day { Day::Tue } };
> [...]

I'm not 100% clear on when this 'anon' keyword is to be applied and when not.

Why is it 'anon role' for anonymous roles but not 'anon enum' for
anonymous enumerations?

If 'anon' isn't strictly required before 'enum', is it still allowed?

// Carl


r29250 - in docs/Perl6/Spec: . S32-setting-library

2009-12-03 Thread pugs-commits
Author: lwall
Date: 2009-12-03 20:00:40 +0100 (Thu, 03 Dec 2009)
New Revision: 29250

Modified:
   docs/Perl6/Spec/S02-bits.pod
   docs/Perl6/Spec/S12-objects.pod
   docs/Perl6/Spec/S32-setting-library/Containers.pod
Log:
make pair values sequences both associative and positional
revise enum mixins to distinguish attribute vs method mixin


Modified: docs/Perl6/Spec/S02-bits.pod
===
--- docs/Perl6/Spec/S02-bits.pod2009-12-03 15:33:14 UTC (rev 29249)
+++ docs/Perl6/Spec/S02-bits.pod2009-12-03 19:00:40 UTC (rev 29250)
@@ -13,8 +13,8 @@
 
 Created: 10 Aug 2004
 
-Last Modified: 23 Nov 2009
-Version: 192
+Last Modified: 3 Dec 2009
+Version: 193
 
 This document summarizes Apocalypse 2, which covers small-scale
 lexical items and typological issues.  (These Synopses also contain
@@ -1151,7 +1151,7 @@
 Set Unordered collection of values that allows no duplicates
 Bag Unordered collection of values that allows duplicates
 PairVal An immutable Pair
-PairValSet  Set of PairVals with no duplicate keys
+PairValSeq  Seq of PairVals with no duplicate keys
 Signature   Function parameters (left-hand side of a binding)
 Parcel  List of syntactic objects
 Capture Function call arguments (right-hand side of a binding)
@@ -1206,7 +1206,7 @@
 Set Associative[Bool]
 Bag Associative[UInt]
 PairVal Associative
-PairValSet  Associative
+PairValSeq  Associative Postional Iterable
 Signature   
 Parcel  Positional
 Capture Positional Associative
@@ -1227,7 +1227,7 @@
 KeySet  KeyHash of Bool (does Set in list/array context)
 KeyBag  KeyHash of UInt (does Bag in list/array context)
 PairA single key-to-value association
-PairSet A Set of Pairs
+PairSeq A Seq of Pairs
 Buf Perl buffer (a stringish array of memory locations)
 IO  Perl filehandle
 Routine Base class for all wrappable executable objects
@@ -1275,7 +1275,7 @@
 replicated the number of times specified by its corresponding value.
 (Use C<.kv> or C<.pairs> to suppress this behavior in list context.)
 
-As with C types, C and C are mutable in their
+As with C types, C and C are mutable in their
 values but not in their keys.  (A key can be a reference to a mutable
 object, but cannot change its C<.WHICH> identity.  In contrast,
 the value may be rebound to a different object, just as a hash
@@ -1288,8 +1288,9 @@
 HashAssociative
 KeySet  KeyHash[Bool]
 KeyBag  KeyHash[UInt]
+KeyHash Associative
 PairAssociative
-PairSet Associative
+PairSeq Associative Postional Iterable
 Buf Stringy
 IO  
 Routine Callable

Modified: docs/Perl6/Spec/S12-objects.pod
===
--- docs/Perl6/Spec/S12-objects.pod 2009-12-03 15:33:14 UTC (rev 29249)
+++ docs/Perl6/Spec/S12-objects.pod 2009-12-03 19:00:40 UTC (rev 29250)
@@ -13,8 +13,8 @@
 
 Created: 27 Oct 2004
 
-Last Modified: 28 Nov 2009
-Version: 93
+Last Modified: 3 Dec 2009
+Version: 94
 
 =head1 Overview
 
@@ -1713,7 +1713,7 @@
 3 ~~ Day# True, using Day as a subset of Int
 Day.mapping # hash of key/value pairs
 
-The C<.mapping> method returns a C that may be used like
+The C<.mapping> method returns a C that may be used like
 a constant hash value:
 
 my enum CoinFace ;
@@ -1747,7 +1747,9 @@
 %e = 1;
 %e = 2;
 
-The enum installer inspects list values for pairs, where the value
+The return value of an anonymous enum is a c.
+
+The enum composer inspects list values for pairs, where the value
 of the pair sets the next value explicitly.  Non-pairs C<++> the
 previous value.  (Str and buf types increment like Perl 5 strings.)
 Since the C<«...»> quoter automatically recognizes
@@ -1782,7 +1784,7 @@
 or the old one.)  Any explicit sub or type definition hides all imported
 enum values of the same name but will produce a warning unless
 C is included.  Note that true() is a built-in function
-and requires an argument, while True is short for C and
+and requires an argument, while C is short for C and
 does not take an argument.
 
 Since non-native enum values know their enum type, they may be used to
@@ -1801,16 +1803,31 @@
 An enum type is not in itself a role type; however, the C
 and C operators know that when a user supplies an enum type,
 it implies the generation of an anonymous mixin role that creates an
-attribute of the enum type along with an accessor.  If we assume
-there is a C role that creates an attribute, then
+an appropriate accessor, read-write if an attribute is being created, and
+read-only otherwise.  It depends on whether you mix in the whole
+or a specific enum value or the whole enum type:
 
+$x = "Today" but Tue;