Skip to content
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

Closed
p6rt opened this issue Jun 8, 2008 · 4 comments
Closed

Improved List.uniq #124

p6rt opened this issue Jun 8, 2008 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 8, 2008

Migrated from rt.perl.org#55484 (status was 'resolved')

Searchable as RT55484$

@p6rt
Copy link
Author

p6rt commented Jun 8, 2008

From @bacek

Hello.

Implements subroutine form of uniq and specifying own comparator.

BTW, List.uniq looks like totally unspecced.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Jun 8, 2008

From @bacek

uniq.diff
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.

@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

From @pmichaud

Applied (with modifications) in r32476, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

@pmichaud - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed Nov 10, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant