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

Make 4 ... 0, 1, 2, 3, 4 (an infix:<...> with a list to the right) do the right thing in Rakudo #1825

Closed
p6rt opened this issue Jun 11, 2010 · 12 comments

Comments

@p6rt
Copy link

p6rt commented Jun 11, 2010

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

Searchable as RT75674$

@p6rt
Copy link
Author

p6rt commented Jun 11, 2010

From @masak

<moritz_> rakudo​: say (4...^5).perl
<p6eval> rakudo d59da8​: OUTPUT«(4, 3, 2, 1)␤»
<moritz_> now I'm confused
<moritz_> rakudo​: say (4 ... 0, 1, 2, 3, 4).perl
<p6eval> rakudo d59da8​: OUTPUT«(4, 3, 2, 1)␤»
<moritz_> why does it throw away all those additional values? bug?
<moritz_> colomon, any idea?
<masak> I'd say it's a bug, yes.
<moritz_> masak​: care to submit it?
* masak submits it
<moritz_> masak​: btw I found it while checking an older bug report of
yours, RT #​72912
<colomon> oh, that's easy. bug
<colomon> well, NYI
<moritz_> ok
<masak> I'll include that in the ticket.

Expected output from both these are, IIUC, (4, 3, 2, 1, 0, 1, 2, 3, 4).

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From dimid@no-more.kiev.ua

fix for this bug into attach

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From dimid@no-more.kiev.ua

0001-fix-an-infix-.-with-a-list-to-the-right-do-right-thi.patch
From a08ad0ed8c8dad01f0ceb39f4d84acbfea6c373e Mon Sep 17 00:00:00 2001
From: Alexey Grebenschikov <dimid@no-more.kiev.ua>
Date: Sat, 12 Jun 2010 18:13:01 +0300
Subject: [PATCH] fix: an infix:<...> with a list to the right do right thing

---
 src/core/operators.pm |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/core/operators.pm b/src/core/operators.pm
index ecdd356..0f984ea 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -345,6 +345,12 @@ our multi sub infix:<...>($lhs, $rhs) {
                 take $y;
             }
         }
+
+        if $rhs ~~ Iterable {
+            for @($rhs) {
+                take $_;
+            }
+        }
     }
 }
 
-- 
1.7.1

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From @jnthn

On Sat Jun 12 08​:16​:42 2010, dimid wrote​:

fix for this bug into attach

Patch applied, awaiting test coverage.

Jonathan

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

@jnthn - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S03-operators/series.t

commit dc653c9531fffc0b0f7ed4ab68cac68200687c53
Author​: dimid <dimid@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sat Jun 12 15​:59​:07 2010 +0000

  [t/spec] Add tests for RT#​75674. infix​:<...> works with a list to the right
 
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31219 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S03-operators/series.t b/t/spec/S03-operators/series.t
index 0123cb6..c0d7d82 100644
--- a/t/spec/S03-operators/series.t
+++ b/t/spec/S03-operators/series.t
@@ -145,6 +145,11 @@ is (16, 8, 4 ... *).batch(5).join(', '), '16, 8, 4, 2, 1', 'geom decreasing';
             'expression with two magic series operators and non-matching end points';
 }
 
+{
+    is ~(4 ... ^5), ~<4 3 2 1 0 1 2 3 4>, '4 ... ^5 works';
+    is ~(4 ... 0, 1, 2, 3, 4), ~<4 3 2 1 0 1 2 3 4>, '4 ... 0, 1, 2, 3,4 works';
+}
+
 done_testing;
 
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From justin.sahs@gmail.com

On Sat Jun 12 08​:35​:16 2010, jnthn@​jnthn.net wrote​:

On Sat Jun 12 08​:16​:42 2010, dimid wrote​:

fix for this bug into attach

Patch applied, awaiting test coverage.

Jonathan

The applied patch works when the lhs is a single integer, e.g. (-5 ...
^5), but fails if the lhs is a list e.g. (4,3,2,1,0 ... ^5). attached
is another patch.

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From justin.sahs@gmail.com

fix.patch
diff --git a/src/core/operators.pm b/src/core/operators.pm
index 0f984ea..10fd569 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -491,6 +491,12 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
                 }
             }
         }
+
+        if $rhs ~~ Iterable {
+            for @($rhs) {
+                take $_;
+            }
+        }
     }
 }
 

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From justin.sahs@gmail.com

Ignore my previous​: didn't notice a repeated element.
Attached is a corrected patch.

For clarity​:
After Alexey's patch​:
(-5 ... ^5) == -5, -4, -3, -2, -1, 0, 0, 1, 2, 3, 4
(4 ... ^5) == 4,3,2,1

After my (new) patch​:
(-5 ... ^5) == -5, -4, -3, -2, -1, 0, 1, 2, 3, 4
(4 ... ^5) == 4,3,2,1,0,1,2,3,4

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From justin.sahs@gmail.com

fix2.patch
diff --git a/src/core/operators.pm b/src/core/operators.pm
index 0f984ea..c09e752 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -347,7 +347,12 @@ our multi sub infix:<...>($lhs, $rhs) {
         }
 
         if $rhs ~~ Iterable {
-            for @($rhs) {
+			my @rest = @($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;
+            for @rest {
                 take $_;
             }
         }
@@ -491,6 +496,15 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
                 }
             }
         }
+
+        if $rhs ~~ Iterable {
+			my @rest = @($rhs);
+			# the first element has already been taken
+			@rest.shift;
+            for @rest {
+                take $_;
+            }
+        }
     }
 }
 

@p6rt
Copy link
Author

p6rt commented Nov 14, 2012

From @coke

On Sat Jun 12 08​:35​:16 2010, jnthn@​jnthn.net wrote​:

On Sat Jun 12 08​:16​:42 2010, dimid wrote​:

fix for this bug into attach

Patch applied, awaiting test coverage.

Jonathan

Tests added to S03-sequence/basic.t (with minor whitespace tweak from TimToady++);

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Nov 14, 2012

@coke - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant