Skip to content

Commit

Permalink
Set|Bag|Mix.new() no longer return set()|bag()|mix()
Browse files Browse the repository at this point in the history
- to pave the way for making "my %h is Set|Bag|Mix" work
- Set|Bag|Mix.new() returning sentinels not considered worthwhile having
  • Loading branch information
lizmat committed Oct 30, 2017
1 parent 6ac2b15 commit aab2b98
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 86 deletions.
20 changes: 0 additions & 20 deletions src/core/Bag.pm
Expand Up @@ -22,27 +22,7 @@ my class Bag does Baggy {
)
}

#--- object creation methods
multi method new(Bag:_:) {
nqp::if(
nqp::eqaddr(self.WHAT,Bag),
bag(),
nqp::create(self)
)
}

#--- interface methods
method SET-SELF(Bag:D: \elems) {
nqp::if(
nqp::elems(elems),
nqp::stmts(
nqp::bindattr(self,::?CLASS,'$!elems',elems),
self
),
bag()
)
}

multi method DELETE-KEY(Bag:D: \k) {
X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw;
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/BagHash.pm
Expand Up @@ -55,9 +55,6 @@ my class BagHash does Baggy {
)
}

#--- object creation methods
multi method new(BagHash:_:) { nqp::create(self) }

#--- introspection methods
method total() { Rakudo::QuantHash.BAG-TOTAL($!elems) }

Expand Down
9 changes: 0 additions & 9 deletions src/core/Baggy.pm
Expand Up @@ -12,15 +12,6 @@ my role Baggy does QuantHash {
# Immutables aspects of Bag/Mix, need to live to Bag/Mix respectively.

#--- interface methods
method SET-SELF(Baggy:D: \elems) {
nqp::stmts(
nqp::if(
nqp::elems(elems),
nqp::bindattr(self,::?CLASS,'$!elems',elems)
),
self
)
}
multi method ACCEPTS(Baggy:U: \other --> Bool:D) {
other.^does(self)
}
Expand Down
30 changes: 24 additions & 6 deletions src/core/Iterable.pm
Expand Up @@ -142,9 +142,15 @@ my role Iterable {
nqp::if(
(my $iterator := iterable.flat.iterator).is-lazy,
Failure.new(X::Cannot::Lazy.new(:action<coerce>,:what(type.^name))),
nqp::create(type).SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-MIX(
nqp::if(
nqp::elems(my $elems := Rakudo::QuantHash.ADD-PAIRS-TO-MIX(
nqp::create(Rakudo::Internals::IterationSet),$iterator
)),
nqp::create(type).SET-SELF($elems),
nqp::if(
nqp::eqaddr(type,Mix),
mix(),
nqp::create(type)
)
)
)
Expand All @@ -156,9 +162,15 @@ my role Iterable {
nqp::if(
(my $iterator := iterable.flat.iterator).is-lazy,
Failure.new(X::Cannot::Lazy.new(:action<coerce>,:what(type.^name))),
nqp::create(type).SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-BAG(
nqp::if(
nqp::elems(my $elems := Rakudo::QuantHash.ADD-PAIRS-TO-BAG(
nqp::create(Rakudo::Internals::IterationSet),$iterator
)),
nqp::create(type).SET-SELF($elems),
nqp::if(
nqp::eqaddr(type,Bag),
bag(),
nqp::create(type)
)
)
)
Expand All @@ -170,9 +182,15 @@ my role Iterable {
nqp::if(
(my $iterator := iterable.flat.iterator).is-lazy,
Failure.new(X::Cannot::Lazy.new(:action<coerce>,:what(type.^name))),
nqp::create(type).SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-SET(
nqp::if(
nqp::elems(my $elems := Rakudo::QuantHash.ADD-PAIRS-TO-SET(
nqp::create(Rakudo::Internals::IterationSet),$iterator
)),
nqp::create(type).SET-SELF($elems),
nqp::if(
nqp::eqaddr(type,Set),
set(),
nqp::create(type)
)
)
)
Expand Down
20 changes: 0 additions & 20 deletions src/core/Mix.pm
Expand Up @@ -4,17 +4,6 @@ my class Mix does Mixy {
has Real $!total-positive;

#--- interface methods
method SET-SELF(Mix:D: \elems) {
nqp::if(
nqp::elems(elems),
nqp::stmts(
nqp::bindattr(self,::?CLASS,'$!elems',elems),
self
),
mix()
)
}

multi method DELETE-KEY(Mix:D: \k) {
X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw;
}
Expand Down Expand Up @@ -46,15 +35,6 @@ my class Mix does Mixy {
)
}

#--- object creation methods
multi method new(Mix:_:) {
nqp::if(
nqp::eqaddr(self.WHAT,Mix),
mix(),
nqp::create(self)
)
}

#--- selection methods
multi method grab($count? --> Real:D) {
X::Immutable.new( method => 'grab', typename => self.^name ).throw;
Expand Down
11 changes: 11 additions & 0 deletions src/core/QuantHash.pm
@@ -1,4 +1,15 @@
my role QuantHash does Associative {

method SET-SELF(QuantHash:D: \elems) {
nqp::stmts(
nqp::if(
nqp::elems(elems),
nqp::bindattr(self,::?CLASS,'$!elems',elems)
),
self
)
}

method Int ( --> Int:D) { self.total.Int }
method Num ( --> Num:D) { self.total.Num }
method Numeric ( --> Numeric:D) { self.total.Numeric }
Expand Down
18 changes: 0 additions & 18 deletions src/core/Set.pm
@@ -1,24 +1,6 @@
my class Set does Setty {
has $!WHICH;

method SET-SELF(\elems) {
nqp::if(
nqp::elems(elems),
nqp::stmts(
nqp::bindattr(self,::?CLASS,'$!elems',elems),
self
),
set()
)
}
multi method new(Set:_:) {
nqp::if(
nqp::eqaddr(self.WHAT,Set),
set(),
nqp::create(self)
)
}

multi method WHICH (Set:D:) {
nqp::if(
nqp::attrinited(self,Set,'$!WHICH'),
Expand Down
10 changes: 0 additions & 10 deletions src/core/SetHash.pm
@@ -1,15 +1,5 @@
my class SetHash does Setty {

method SET-SELF(\elems) {
nqp::stmts(
nqp::if(
nqp::elems(elems),
nqp::bindattr(self,::?CLASS,'$!elems',elems)
),
self
)
}

#--- selector methods

multi method grab(SetHash:D:) {
Expand Down

0 comments on commit aab2b98

Please sign in to comment.