Permalink
Browse files

simplistic List.ACCEPTS, fix Array.push to return self

  • Loading branch information...
1 parent 399c991 commit c47b8167d2b6578adae07328e6889f4051fbedb2 @moritz moritz committed Jul 13, 2011
Showing with 13 additions and 1 deletion.
  1. +11 −0 src/core/List.pm
  2. +1 −0 src/core/Parcel.pm
  3. +1 −1 t/spectest.data
View
@@ -135,6 +135,7 @@ class List does Positional {
my $pos = self.elems;
fail '.push on infinite lists NYI' if $!nextiter.defined;
self.STORE_AT_POS($pos++, @values.shift) while @values;
+ self;
}
method roll($n is copy = 1) {
@@ -189,6 +190,16 @@ class List does Positional {
self[$index];
}
+ multi method ACCEPTS(List:D: $topic) {
+ my @t = $topic.list;
+ # TODO: Whatever-DWIMmery
+ return False unless self.elems == @t.elems;
+ for ^self.elems {
+ return False unless self.at_pos($_) === @t[$_];
+ }
+ True;
+ }
+
method classify(&test) {
my %result;
for @.list {
View
@@ -4,6 +4,7 @@ my class Parcel does Positional {
# has $!storage; # RPA of Parcel's elements
multi method Str(Parcel:D:) { self.flat.Str }
+ multi method ACCEPTS(Parcel:D: $topic) { self.list.ACCEPTS($topic) }
method Numeric() { self.flat.elems }
method Capture() { self } # XXX CHEAT CHEAT CHEAT
View
@@ -474,7 +474,7 @@ S32-array/exists.t
# S32-array/kv.t # err: Method 'kv' not found for invocant of class 'Array'
# S23-array/pairs.t #err: Method 'pairs' not found for invocant of class 'Array'
S32-array/pop.t
-# S32-array/push.t # err: No applicable candidates found to dispatch to for 'ACCEPTS'
+S32-array/push.t
# S32-array/rotate.t # err: Method 'rotate' not found for invocant of class 'Array'
S32-array/shift.t
# S32-array/splice.t # err: Could not find sub &splice

0 comments on commit c47b816

Please sign in to comment.