# New Ticket Created by Vasily Chekalkin
# Please include the string: [perl #55484]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=55484 >
Hello.
Implements subroutine form of uniq and specifying own comparator.
BTW, List.uniq looks like totally unspecced.
--
Bacek.
diff --git a/languages/perl6/src/classes/List.pir b/languages/perl6/src/classes/List.pir
index b9b5107..b4056ac 100644
--- a/languages/perl6/src/classes/List.pir
+++ b/languages/perl6/src/classes/List.pir
@@ -624,7 +624,9 @@
# TODO Rewrite it. It's too naive.
.namespace ['List']
-.sub uniq :method
+.sub 'uniq' :method
+ .param pmc comparer :optional
+ .param int has_comparer :opt_flag
.local pmc ulist
.local pmc key
.local pmc val
@@ -634,6 +636,9 @@
.local int ulen
.local int ui
+ if has_comparer goto do_work
+ comparer = get_hll_global 'infix:eq'
+ do_work:
ulist = new 'List'
len = self.'elems'()
i = 0
@@ -649,7 +654,8 @@
if ui == ulen goto inner_loop_done
uval = ulist[ui]
- if uval == val goto found
+ $I0 = comparer(uval, val)
+ if $I0 goto found
inc ui
goto inner_loop
@@ -667,6 +673,21 @@
.end
+.namespace []
+.sub 'uniq' :multi(Closure)
+ .param pmc comparer
+ .param pmc values :slurpy
+ .return values.'uniq'(comparer)
+.end
+
+.sub 'uniq' :multi()
+ .param pmc values :slurpy
+ .return values.'uniq'()
+.end
+
+
+.namespace ['List']
+
=item values()
Returns a List containing the values of the invocant.