Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expand Set, KeySet, Bag, and KeyBag .new to specially handle (Key)Set…
…s and maybe (Key)Bags. Not 100% clear if this is to spec or not (I think the only mention was in the spectests).
  • Loading branch information
colomon committed Feb 6, 2012
1 parent c83b9cd commit 256172a
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions lib/CORE.setting
Expand Up @@ -45,6 +45,8 @@ my class Whatever { ... }
my class IO { ... }
my class ObjAt { ... }
my class Proxy { ... }
my class KeySet { ... }
my class KeyBag { ... }
grammar Niecza::NumSyntax { ... }
# }}}
# Important inlinable definitions {{{
Expand Down Expand Up @@ -1975,7 +1977,15 @@ class Set does Associative {
# Constructor
method new(*@args --> Set) {
self.bless(*, :elems(%(@args X=> True)));
my %e;
for @args {
when Set | KeySet { for .keys -> $key { %e{$key} = True; } }
# when Bag | KeyBag { for .keys -> $key {
# if %e{$key}:exists { %e{$key} += $_{$key} } else { %e{$key} = $_{$key} }
# } }
default { %e{$_} = True; }
}
self.bless(*, :elems(%e));
}
submethod BUILD (%!elems) { }
Expand Down Expand Up @@ -2077,7 +2087,15 @@ class KeySet does Associative {
# Constructor
method new(*@args --> KeySet) {
self.bless(*, :elems(%(@args X=> True)));
my %e;
for @args {
when Set | KeySet { for .keys -> $key { %e{$key} = True; } }
# when Bag | KeyBag { for .keys -> $key {
# if %e{$key}:exists { %e{$key} += $_{$key} } else { %e{$key} = $_{$key} }
# } }
default { %e{$_} = True; }
}
self.bless(*, :elems(%e));
}
submethod BUILD (%!elems) { }
Expand Down Expand Up @@ -2108,7 +2126,10 @@ class Bag does Associative {
method new(*@args --> Bag) {
my %e;
for @args {
when Set { for .keys -> $key { %e{$key}++; } }
when Set | KeySet { for .keys -> $key { %e{$key}++; } }
when Bag | KeyBag { for .keys -> $key {
if %e{$key}:exists { %e{$key} += $_{$key} } else { %e{$key} = $_{$key} }
} }
default { %e{$_}++; }
}
self.bless(*, :elems(%e));
Expand Down Expand Up @@ -2151,7 +2172,10 @@ class KeyBag does Associative {
method new(*@args --> KeyBag) {
my %e;
for @args {
when Set { for .keys -> $key { %e{$key}++; } }
when Set | KeySet { for .keys -> $key { %e{$key}++; } }
when Bag | KeyBag { for .keys -> $key {
if %e{$key}:exists { %e{$key} += $_{$key} } else { %e{$key} = $_{$key} }
} }
default { %e{$_}++; }
}
self.bless(*, :elems(%e));
Expand Down

0 comments on commit 256172a

Please sign in to comment.