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
Fix Parcel.sort (fixes the very first example in http://cloud.github.com/downloads/perl6/book/book-2010-04.pdf) and Hash.sort #1686
Comments
From quester.pm@gmail.comHello, I noticed that certain uses of sort no longer work in Rakudo after the ng my @sorted = @names.sort({ %sets{$_} }).sort({ %games{$_} }).reverse fails, as does this trivial example, $ rakudo -e '<1 3 4 2>.sort({-$^a}).say' The attached patch fixes the problem as follows: 1. In Seq.pm, the sort method is modified to make a ResizablePMCArray to Note that one test in t/spec/S32-list/sort.t fails... not ok 4 - array of mixed numbers including Inf/NaN This is due to NaN sorting greater than Inf, rather than less than -Inf. $ perl6 -e 'say NaN <=> Inf' ... I'm not sure that is appropriate to "fix" it in the code; it might be Please let me know if you have any comments or concerns or would rather see Best regards, |
From quester.pm@gmail.com0001-Fix-Parcel.sort-fixes-the-very-first-example-in-http.patchFrom 37d13f5c76c35d03a69b6ff27d9f29b7699bbef0 Mon Sep 17 00:00:00 2001
From: quester <quester.pm@gmail.com>
Date: Tue, 13 Apr 2010 00:03:45 -1000
Subject: [PATCH] Fix Parcel.sort (fixes the very first example in http://cloud.github.com/downloads/perl6/book/book-2010-04.pdf) and Hash.sort
---
src/core/Hash.pm | 9 +++++++++
src/core/Parcel.pm | 2 ++
src/core/Seq.pm | 10 ++++++++--
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/core/Hash.pm b/src/core/Hash.pm
index 29f6f4c..31ca6aa 100644
--- a/src/core/Hash.pm
+++ b/src/core/Hash.pm
@@ -101,4 +101,13 @@ role Hash is EnumMap {
self.{$key} = $value;
}
}
+
+ multi method sort(&by = &infix:<cmp>) {
+ self.pairs.sort(&by)
+ }
+
}
+
+multi sub sort (%h, :&by = &infix:<cmp>) { %h.pairs.sort(&by) }
+multi sub sort (&by, %h) { %h.pairs.sort(&by) }
+
diff --git a/src/core/Parcel.pm b/src/core/Parcel.pm
index 22014b0..3f060ac 100644
--- a/src/core/Parcel.pm
+++ b/src/core/Parcel.pm
@@ -5,6 +5,8 @@ augment class Parcel {
method rotate(Int $n = 1) { self.Seq.rotate($n) }
+ multi method sort(&by = &infix:<cmp>) { self.Seq.sort(&by) }
+
multi method ACCEPTS($x) {
# smart-matching against Nil
if self.elems == 0 {
diff --git a/src/core/Seq.pm b/src/core/Seq.pm
index 3b14404..cac25c2 100644
--- a/src/core/Seq.pm
+++ b/src/core/Seq.pm
@@ -61,17 +61,20 @@ augment class Seq {
# of indices (from 0 to $list.elems), then use that RPA
# as a slice into self.
+ my $index_PARROT_RPA = pir::new__PS("ResizablePMCArray");
+ pir::push__vPP($index_PARROT_RPA, $_) for ^self.elems;
+
# If &by.arity < 2, then it represents a block to be applied
# to the elements to obtain the values for sorting.
if (&by.?arity // 2) < 2 {
my $list = self.map(&by).eager;
- self[(^pir::elements($list)).eager.sort(
+ self[$index_PARROT_RPA.sort(
-> $a, $b { $list[$a] cmp $list[$b] || $a <=> $b }
)];
}
else {
my $list = self.eager;
- self[(^pir::elements($list)).eager.sort(
+ self[$index_PARROT_RPA.sort(
-> $a, $b { &by($list[$a],$list[$b]) || $a <=> $b }
)];
}
@@ -87,4 +90,7 @@ augment class Seq {
}
}
+multi sub sort (@x, :&by = &infix:<cmp>) { @x.sort(&by) }
+multi sub sort (&by, @x) { @x.sort(&by) }
+
# vim: ft=perl6
--
1.6.6.1
|
From @japhbOn Tue, 2010-04-13 at 05:42 -0700, Ira Byerly wrote:
In that case, the spec test should not care where the NaN sorts -- it Probably the easiest solution is just to do the sort, check that it -'f |
The RT System itself - Status changed from 'new' to 'open' |
From @moritzThank you very much, I applied the patch after removing a trailing Cheers, |
@moritz - Status changed from 'open' to 'resolved' |
From @markjreedSeems like both NaN <= $x and NaN >= $x should return false for any On Tuesday, April 13, 2010, Geoffrey Broadwell <geoff@broadwell.org> wrote:
-- |
From @kylehaOn Tue, Apr 13, 2010 at 4:51 PM, Mark J. Reed <markjreed@gmail.com> wrote:
That reminds me of a bug I wrote in C++ one time. I had overloaded Kyle. |
Migrated from rt.perl.org#74334 (status was 'resolved')
Searchable as RT74334$
The text was updated successfully, but these errors were encountered: