Permalink
Browse files

Part 2 of bringing Set/Bag up to spec again

  • Loading branch information...
1 parent bc39750 commit 7eacce52e0a4a0547c80b45c62525cd13ed08f07 @lizmat lizmat committed Oct 3, 2013
View
@@ -238,10 +238,10 @@ my class Any { # declared in BOOTSTRAP
}
method FLATTENABLE_HASH() { nqp::hash() }
- method Set() { Set.new-fp(self.list) }
- method KeySet() { KeySet.new-fp(self.list) }
- method Bag() { Bag.new-fp(self.list) }
- method KeyBag() { KeyBag.new-fp(self.list) }
+ method Set() { Set.new-fp(self.list) }
+ method SetHash() { SetHash.new-fp(self.list) }
+ method Bag() { Bag.new-fp(self.list) }
+ method BagHash() { BagHash.new-fp(self.list) }
}
Metamodel::ClassHOW.exclude_parent(Any);
View
@@ -27,5 +27,5 @@ my class Bag does Baggy {
}
method Bag { self }
- method KeyBag { KeyBag.new-fp(nqp::getattr(self, Bag, '%!elems').values) }
+ method BagHash { BagHash.new-fp(nqp::getattr(self, Bag, '%!elems').values) }
}
View
@@ -1,15 +1,15 @@
-my class KeyBag does Baggy {
+my class BagHash does Baggy {
method at_key($k) {
Proxy.new(
FETCH => {
my $key := $k.WHICH;
- my $elems := nqp::getattr(self, KeyBag, '%!elems');
+ my $elems := nqp::getattr(self, BagHash, '%!elems');
$elems.exists_key($key) ?? $elems{$key}.value !! 0;
},
STORE => -> $, $value {
if $value > 0 {
- (nqp::getattr(self, KeyBag, '%!elems'){$k.WHICH}
+ (nqp::getattr(self, BagHash, '%!elems'){$k.WHICH}
//= ($k => 0)).value = $value;
}
elsif $value == 0 {
@@ -24,12 +24,12 @@ my class KeyBag does Baggy {
}
method delete($k) { # is DEPRECATED doesn't work in settings
- once DEPRECATED("Method 'KeyBag.delete'","the :delete adverb");
+ once DEPRECATED("Method 'BagHash.delete'","the :delete adverb");
self.delete_key($k);
}
method delete_key($k) {
my $key := $k.WHICH;
- my $elems := nqp::getattr(self, KeyBag, '%!elems');
+ my $elems := nqp::getattr(self, BagHash, '%!elems');
if $elems.exists_key($key) {
my $value = $elems{$key}.value;
$elems.delete_key($key);
@@ -43,12 +43,12 @@ my class KeyBag does Baggy {
method Bag (:$view) {
if $view {
my $bag := nqp::create(Bag);
- $bag.BUILD( :elems(nqp::getattr(self, KeyBag, '%!elems')) );
+ $bag.BUILD( :elems(nqp::getattr(self, BagHash, '%!elems')) );
$bag;
}
else {
- Bag.new-fp(nqp::getattr(self, KeyBag, '%!elems').values);
+ Bag.new-fp(nqp::getattr(self, BagHash, '%!elems').values);
}
}
- method KeyBag { self }
+ method BagHash { self }
}
View
@@ -181,9 +181,9 @@ my role Baggy does Associative {
}
only sub infix:<(.)>(**@p) {
- my $keybag = @p[0] ~~ KeyBag
- ?? KeyBag.new-fp(@p.shift.pairs)
- !! @p.shift.KeyBag;
+ my $keybag = @p[0] ~~ BagHash
+ ?? BagHash.new-fp(@p.shift.pairs)
+ !! @p.shift.BagHash;
for @p.map(*.Bag(:view)) -> $bag {
$bag{$_}
?? $keybag{$_} *= $bag{$_}
@@ -200,9 +200,9 @@ only sub infix:<<"\x228D">>(|p) {
only sub infix:<(+)>(**@p) {
return bag() unless @p;
- my $keybag = @p[0] ~~ KeyBag
- ?? KeyBag.new-fp(@p.shift.pairs)
- !! @p.shift.KeyBag;
+ my $keybag = @p[0] ~~ BagHash
+ ?? BagHash.new-fp(@p.shift.pairs)
+ !! @p.shift.BagHash;
for @p.map(*.Bag(:view)) -> $bag {
$keybag{$_} += $bag{$_} for $bag.keys;
}
View
@@ -21,7 +21,7 @@ my class Set does Setty {
}
method Set { self }
- method KeySet { KeySet.new(self.keys) }
+ method SetHash { SetHash.new(self.keys) }
}
sub set(*@args --> Set) { Set.new(@args) }
View
@@ -1,27 +1,27 @@
-my class KeySet does Setty {
+my class SetHash does Setty {
method at_key($k --> Bool) {
Proxy.new(
FETCH => {
- so nqp::getattr(self, KeySet, '%!elems').exists_key($k.WHICH);
+ so nqp::getattr(self, SetHash, '%!elems').exists_key($k.WHICH);
},
STORE => -> $, $value {
if $value {
- nqp::getattr(self, KeySet, '%!elems'){$k.WHICH} = $k;
+ nqp::getattr(self, SetHash, '%!elems'){$k.WHICH} = $k;
}
else {
- nqp::getattr(self, KeySet, '%!elems').delete_key($k.WHICH);
+ nqp::getattr(self, SetHash, '%!elems').delete_key($k.WHICH);
}
so $value;
});
}
method delete($k) { # is DEPRECATED doesn't work in settings
- once DEPRECATED("Method 'KeySet.delete'","the :delete adverb");
+ once DEPRECATED("Method 'SetHash.delete'","the :delete adverb");
self.delete_key($k);
}
method delete_key($k --> Bool) {
- my $elems := nqp::getattr(self, KeySet, '%!elems');
+ my $elems := nqp::getattr(self, SetHash, '%!elems');
my $key := $k.WHICH;
return False unless $elems.exists_key($key);
@@ -32,13 +32,13 @@ my class KeySet does Setty {
method Set (:$view) {
if $view {
my $set := nqp::create(Set);
- $set.BUILD( :elems(nqp::getattr(self, KeySet, '%!elems')) );
+ $set.BUILD( :elems(nqp::getattr(self, SetHash, '%!elems')) );
$set;
}
else {
Set.new(self.keys);
}
}
- method KeySet { self }
+ method SetHash { self }
}
View
@@ -105,7 +105,7 @@ only sub infix:<<"\x220C">>($a, $b --> Bool) {
only sub infix:<(|)>(**@p) {
if @p.grep(Baggy) {
- my $keybag = KeyBag.new;
+ my $keybag = BagHash.new;
for @p.map(*.Bag(:view)) -> $bag {
$keybag{$_} max= $bag{$_} for $bag.keys;
}
@@ -124,9 +124,9 @@ only sub infix:<(&)>(**@p) {
return set() unless @p;
if @p.grep(Baggy) {
- my $keybag = @p[0] ~~ KeyBag
- ?? KeyBag.new-fp(@p.shift.pairs)
- !! @p.shift.KeyBag;
+ my $keybag = @p[0] ~~ BagHash
+ ?? BagHash.new-fp(@p.shift.pairs)
+ !! @p.shift.BagHash;
for @p.map(*.Bag(:view)) -> $bag {
$bag{$_}
?? $keybag{$_} min= $bag{$_}
@@ -136,9 +136,9 @@ only sub infix:<(&)>(**@p) {
$keybag.Bag(:view);
}
else {
- my $keyset = @p[0] ~~ KeySet
- ?? KeySet.new(@p.shift.keys)
- !! @p.shift.KeySet;
+ my $keyset = @p[0] ~~ SetHash
+ ?? SetHash.new(@p.shift.keys)
+ !! @p.shift.SetHash;
for @p.map(*.Set(:view)) -> $set {
$set{$_} || $keyset.delete_key($_) for $keyset.keys;
}
@@ -154,9 +154,9 @@ only sub infix:<(-)>(**@p) {
return set() unless @p;
if @p[0] ~~ Baggy {
- my $keybag = @p[0] ~~ KeyBag
- ?? KeyBag.new-fp(@p.shift.pairs)
- !! @p.shift.KeyBag;
+ my $keybag = @p[0] ~~ BagHash
+ ?? BagHash.new-fp(@p.shift.pairs)
+ !! @p.shift.BagHash;
for @p.map(*.Bag(:view)) -> $bag {
$bag{$_} < $keybag{$_}
?? $keybag{$_} -= $bag{$_}
@@ -166,9 +166,9 @@ only sub infix:<(-)>(**@p) {
$keybag.Bag(:view);
}
else {
- my $keyset = @p[0] ~~ KeySet
- ?? KeySet.new(@p.shift.keys)
- !! @p.shift.KeySet;
+ my $keyset = @p[0] ~~ SetHash
+ ?? SetHash.new(@p.shift.keys)
+ !! @p.shift.SetHash;
for @p.map(*.Set(:view)) -> $set {
$set{$_} && $keyset.delete_key($_) for $keyset.keys;
}
View
@@ -3,19 +3,20 @@
# Code/Block/Routine/Sub/Method and Str/Int/Num. They are built in BOOTSTRAP.pm
# in Perl6::Metamodel for now, though should be a BEGIN block in CORE.setting
# in the end.
-my class Bag { ... }
-my class KeyBag { ... }
-my class KeySet { ... }
-my class Set { ... }
my class Seq is List does Positional { }
my class Exception { ... }
my class X::AdHoc { ... }
my class FatRat { ... }
my class Enum { ... }
my class X::OutOfRange { ... }
-my role Baggy { ... }
my role Setty { ... }
+my class Set { ... }
+my class SetHash { ... }
+
+my role Baggy { ... }
+my class Bag { ... }
+my class BagHash { ... }
sub DYNAMIC(\name) is rw {
my Mu $x := nqp::getlexdyn(nqp::unbox_s(name));
@@ -185,12 +185,12 @@ CORE_SOURCES = \
src/core/Temporal.pm \
src/core/EXPORTHOW.pm \
src/core/Pod.pm \
- src/core/Baggy.pm \
- src/core/Bag.pm \
- src/core/KeyBag.pm \
src/core/Setty.pm \
src/core/Set.pm \
- src/core/KeySet.pm \
+ src/core/SetHash.pm \
+ src/core/Baggy.pm \
+ src/core/Bag.pm \
+ src/core/BagHash.pm \
src/core/ObjAt.pm \
src/core/Version.pm \
src/core/ForeignCode.pm \
@@ -231,12 +231,12 @@ CORE_SOURCES = \
src/core/Temporal.pm \
src/core/EXPORTHOW.pm \
src/core/Pod.pm \
- src/core/Baggy.pm \
- src/core/Bag.pm \
- src/core/KeyBag.pm \
src/core/Setty.pm \
src/core/Set.pm \
- src/core/KeySet.pm \
+ src/core/SetHash.pm \
+ src/core/Baggy.pm \
+ src/core/Bag.pm \
+ src/core/BagHash.pm \
src/core/ObjAt.pm \
src/core/Version.pm \
src/core/ForeignCode.pm \

0 comments on commit 7eacce5

Please sign in to comment.