Re: Call for review: traits, lift

2009-05-05 Thread Larry Wall
On Sun, May 03, 2009 at 08:20:17PM +0200, Moritz Lenz wrote:
: If I understood the specs correctly, variables can be lifted, so you can
: write
: 
: sub f() {lift $a + $b};
: {
: my $a is context = 3;
: my $b is context = 4;
: say f();
: }
: 
: Is that correct?

I think so.

: And if yes, do these variables need to be context variables?

Excellent question.  I think the conservative thing to say is yes,
but it's possible that the lift mechanism can't easily distinguish,
unless it happens to use the same lookup that context vars use.
But if we don't require the context declaration, it basically gives
any called routine carte blanche on modifying your variables, which
is probably a bad thing.

So leave it in for now, I guess.

Larry


Re: Call for review: traits, lift

2009-05-05 Thread Daniel Ruoso
Em Dom, 2009-05-03 às 21:15 -0700, Larry Wall escreveu:
 On Sun, May 03, 2009 at 08:20:17PM +0200, Moritz Lenz wrote:
 : If I understood the specs correctly, variables can be lifted, so you can
 : write
 : 
 : sub f() {lift $a + $b};
 : {
 : my $a is context = 3;
 : my $b is context = 4;
 : say f();
 : }
 : 
 : Is that correct?
 : And if yes, do these variables need to be context variables?
 Excellent question.  I think the conservative thing to say is yes,
 but it's possible that the lift mechanism can't easily distinguish,

In fact, i really think there isn't a sane way of distinguishing...
lifting really means looking up from the perspective of the caller, so
you see what the caller sees, so no need for $a and $b to be context...

daniel



r26685 - docs/Perl6/Spec/S32-setting-library

2009-05-05 Thread pugs-commits
Author: lwall
Date: 2009-05-06 00:20:38 +0200 (Wed, 06 May 2009)
New Revision: 26685

Modified:
   docs/Perl6/Spec/S32-setting-library/Containers.pod
Log:
[Containers] some work on various structures related to KeyHash
define .pick to work rationally on structures whose values represent weights.


Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod
===
--- docs/Perl6/Spec/S32-setting-library/Containers.pod  2009-05-05 17:32:04 UTC 
(rev 26684)
+++ docs/Perl6/Spec/S32-setting-library/Containers.pod  2009-05-05 22:20:38 UTC 
(rev 26685)
@@ -15,8 +15,8 @@
 Moritz Lenz mor...@faui2k3.org
Tim Nelson wayl...@wayland.id.au
  Date:  19 Feb 2009 extracted from S29-functions.pod
- Last Modified: 3 May 2009
- Version:   6
+ Last Modified: 5 May 2009
+ Version:   7
 
 The document is a draft.
 
@@ -674,17 +674,11 @@
 
 =back
 
-=head2 Tieable
-
-role Tieable {...}
-
 =head1 Classes
 
 This documents Buf, List, Seq, Range, Set, Bag, Junction, Array, Hash, 
KeyHash, KeySet, 
 KeyBag, Pair, and Mapping.  
 
-XXX So where are KeySet and KeyBag.
-
 =head2 Seq
 
 class Seq does Positional {...}
@@ -703,10 +697,15 @@
 
 class Buf does Positional {...}
 
+A mutable container for an array of integer values in contiguous
+memory.
+
 =head2 Pair
 
 class Pair does Associative {...}
 
+The value of a pair is mutable; the key is not.
+
 =item invert
 
 our List multi method invert ( $pair: ) is export {
@@ -717,18 +716,76 @@
 
 class Mapping does Associative {...}
 
+An immutable hash value, essentially.  The keys may
+not contain duplicates, while the values may.
+
 =head2 Set
 
 class Set does Associative {...}
 
+A set of unique values.  When used as a hash always treats the set's
+values as the keys of the hash, returning CTrue for set elements.
+See CKeySet for a container that can represent different sets
+as keys are added or delete.
+
+=over
+
+=item pick
+
+ our multi method pick ( $set: Int $num = 1, Bool :$repl )
+ our multi method pick ( $set: Whatever, Bool :$repl )
+
+Like an ordinary list pick, but returns keys of the bag weighted by
+values, as if the keys were replicated the number of times indicated
+by the corresponding value and then list pick used. CKeySet is the
+mutable form of CSet.  A CSet responds to hash operators as
+if it were a CHash of True.
+
+=back
+
+=head2 KeySet
+
+A mutable Set container, represented as CKeyHash of True.
+
 =head2 Bag
 
 class Bag does Associative {...}
 
+=over
+
+=item pick
+
+ our multi method pick ( $bag: Int $num = 1, Bool :$repl )
+ our multi method pick ( $bag: Whatever, Bool :$repl )
+
+Like an ordinary list pick, but returns keys of the bag weighted by
+values, as if the keys were replicated the number of times indicated
+by the corresponding value and then list pick used.  CKeyBag is the
+mutable form of CBag.  A CBag responds to hash operators as
+if it were a CHash of UInt.
+
+=back
+
+=head2 KeyBag
+
+A mutable CBag container, represented as CKeyHash of UInt.
+
 =head2 KeyHash
 
 class KeyHash does Associative {...}
 
+A KeyHash represents a mutable set of values, represented as the keys
+of a CHash.  When asked to behave as a list it ignores its values
+and returns only C.keys.  CKeySet and CKeyBag are derived from
+this type, but constrain their values to be CBool and CUInt,
+respectively.  A CKeyHash automatically deletes any key whose
+value goes false.
+
+=head2 KeyWeight
+
+A CKeyHash of Num; like a CKeyBag but may have non-integral
+weights for use in weighted picking.
+
 =head2 junction
 
 All method calls on junctions autothread because the type provides no public 
methods.