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
Series of letters doesn't stop at end point #1754
Comments
From @moritz21:34 <@moritz_> rakudo: say 'a'...'z' Should only go up to z. Moritz |
From @kylehaThis is an automatically generated mail to inform you that tests are now available in t/spec/S03-operators/series-simple.t commit b3d941a4f9a902c1b2fa7619dd68f832a2fbb802 test for RT#74990 Inline Patchdiff --git a/t/spec/S03-operators/series-simple.t b/t/spec/S03-operators/series-simple.t
index 5c74ad4..46653ba 100644
--- a/t/spec/S03-operators/series-simple.t
+++ b/t/spec/S03-operators/series-simple.t
@@ -73,4 +73,8 @@ is ('c', { $_ } ... *).batch(10).join(', '), 'c, c, c, c, c, c, c, c, c, c', 'se
is ('c', 'c' ... *).batch(10).join(', '), 'c, c, c, c, c, c, c, c, c, c', 'series started with two identical letters';
is ('c', 'c', 'c' ... *).batch(10).join(', '), 'c, c, c, c, c, c, c, c, c, c', 'series started with three identical letters';
-done_testing;
|
The RT System itself - Status changed from 'new' to 'open' |
From justin.sahs@gmail.comThe problem was that 'z' cmp 'aa' = 1, because cmp is lexicographic Patch attached. NOTE: THIS PATCH ASSUMES MY PATCH FROM #75674 HAS |
From justin.sahs@gmail.com74990.patchdiff --git a/src/core/operators.pm b/src/core/operators.pm
index c09e752..5c6c220 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -313,6 +313,17 @@ class Whatever { ... }
# the magic one that handles stuff like
# 'a' ... 'z' and 'z' ... 'a'
our multi sub infix:<...>($lhs, $rhs) {
+ # in character sequences e.g. 'a' ... 'z', strings
+ # are not compared in their normal lexicographic
+ # order; in particular, shorter strings are always
+ # before longer strings, e.g. 'z' < 'aa'.
+ my multi sub infix:<ccmp>(Str $a, Str $b) {
+ $a.chars cmp $b.chars || $a cmp $b;
+ }
+ my multi sub infix:<ccmp>($a, $b) {
+ $a cmp $b;
+ }
+
if $rhs ~~ Whatever {
my $i = $lhs;
return gather {
@@ -325,22 +336,22 @@ our multi sub infix:<...>($lhs, $rhs) {
gather {
take $lhs;
- if ($lhs cmp $rhs) == 1 {
+ if ($lhs ccmp $rhs) == 1 {
my $x = $lhs;
# since my $a = 'a'; $a-- gives
# "Decrement out of range" we can't easily
# decrement over our target, which is why the
# case of going backwards is slighly more complicated
# than going forward
- while (--$x cmp $rhs) == 1 {
+ while (--$x ccmp $rhs) == 1 {
# need to make a fresh copy here because of RT #62178
my $y = $x;
take $y;
}
- take $x if ($x cmp $rhs) == 0;
- } elsif ($lhs cmp $rhs) == -1 {
+ take $x if ($x ccmp $rhs) == 0;
+ } elsif ($lhs ccmp $rhs) == -1 {
my $x = $lhs;
- while (++$x cmp $rhs) <= 0 {
+ while (++$x ccmp $rhs) <= 0 {
my $y = $x;
take $y;
}
@@ -351,7 +362,7 @@ our multi sub infix:<...>($lhs, $rhs) {
# 1 cmp 1,2,3 == -1, rather than 0,
# so if $lhs cmp $rhs == -1, the first element
# of @rest has already been taken
- @rest.shift if $lhs cmp $rhs == -1;
+ @rest.shift if $lhs ccmp $rhs == -1;
for @rest {
take $_;
}
@@ -414,8 +425,19 @@ our multi sub infix:<...>(Code $lhs, $rhs) {
}
our multi sub infix:<...>(@lhs is copy, $rhs) {
+ # in character sequences e.g. 'a' ... 'z', strings
+ # are not compared in their normal lexicographic
+ # order; in particular, shorter strings are always
+ # before longer strings, e.g. 'z' < 'aa'.
+ my multi sub infix:<ccmp>(Str $a, Str $b) {
+ $a.chars cmp $b.chars || $a cmp $b;
+ }
+ my multi sub infix:<ccmp>($a, $b) {
+ $a cmp $b;
+ }
+
my sub succ-or-pred($lhs, $rhs) {
- if $rhs ~~ Whatever || $lhs cmp $rhs != 1 {
+ if $rhs ~~ Whatever || $lhs ccmp $rhs != 1 {
-> $x { $x.succ };
} else {
-> $x { $x.pred };
@@ -423,7 +445,7 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
}
my sub succ-or-pred2($lhs0, $lhs1, $rhs) {
- if $lhs1 cmp $lhs0 == 0 {
+ if $lhs1 ccmp $lhs0 == 0 {
$next = { $_ };
} else {
$next = succ-or-pred($lhs1, $rhs);
@@ -477,15 +499,15 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
@args.push($v) if $i >= @lhs.elems - $top;
}
- if !$limit.defined || $limit cmp $j != 0 {
+ if !$limit.defined || $limit ccmp $j != 0 {
loop {
my $i = $next.(|@args);
my $j = $i;
my $cur_cmp = 1;
if $limit.defined {
- $cur_cmp = $limit cmp $j;
- last if (@args[@args.elems - 1] cmp $limit) == $cur_cmp;
+ $cur_cmp = $limit ccmp $j;
+ last if (@args[@args.elems - 1] ccmp $limit) == $cur_cmp;
}
take $j;
last if $cur_cmp == 0;
|
From @thundergnatThis is Rakudo Perl 6, version 2010.11 built on parrot 2.10.1
Works ok locally should be closable if tests have been added to roast. |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#74990 (status was 'resolved')
Searchable as RT74990$
The text was updated successfully, but these errors were encountered: