New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved List.uniq #124
Labels
Comments
From @bacekHello. Implements subroutine form of uniq and specifying own comparator. BTW, List.uniq looks like totally unspecced. -- |
From @bacekuniq.diffdiff --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.
|
From @pmichaudApplied (with modifications) in r32476, thanks! Pm |
@pmichaud - Status changed from 'new' to 'resolved' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Migrated from rt.perl.org#55484 (status was 'resolved')
Searchable as RT55484$
The text was updated successfully, but these errors were encountered: