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

support non-numeric args to rhs of xx #1970

Closed
p6rt opened this issue Jul 26, 2010 · 8 comments
Closed

support non-numeric args to rhs of xx #1970

p6rt opened this issue Jul 26, 2010 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 26, 2010

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

Searchable as RT76720$

@p6rt
Copy link
Author

p6rt commented Jul 26, 2010

From @felliott

Hello,

xx hangs if a non-numeric value appears on the right hand side​:

my @​a = "b" xx "monkey";

my @​c = <a b c>
my @​d = "e" xx @​c;

Attached is a patch which corrects this while still supporting a Whatever argument like so​:

my @​f = <a b c> Z (1 xx *); # @​f is <a 1 b 1 c 1>

I've added fudged spectests to S03-operators/repeat.t and S05-transliteration/trans.t (this bug also causes .trans('x' => '') to hang).

Cheers,
Fitz Elliott

@p6rt
Copy link
Author

p6rt commented Jul 26, 2010

From @felliott

0001-force-xx-op-to-numify-rhs-except-Whatevers.patch
From 60ff703ca544041436f77df5c6dd62add1167fe2 Mon Sep 17 00:00:00 2001
From: Fitz Elliott <felliott@virginia.edu>
Date: Sun, 25 Jul 2010 23:21:39 -0400
Subject: [PATCH] force xx op to numify rhs except Whatevers

---
 src/core/operators.pm |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/core/operators.pm b/src/core/operators.pm
index 43a1fa8..74f8c23 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -267,10 +267,17 @@ our multi infix:<ge>($a, $b) {
 }
 
 # XXX Lazy version would be nice in the future too.
+class Whatever { ... }
+
+our multi infix:<xx>(Mu \$item, Whatever) {
+    (1..*).map( { $item } )
+}
+
 our multi infix:<xx>(Mu \$item, $n) {
-    (1..$n).map( { $item } )
+    (1..+$n).map( { $item } )
 }
 
+
 our multi prefix:<|>(@a) { @a.Capture }
 our multi prefix:<|>(%h) { %h.Capture }
 our multi prefix:<|>(Capture $c) { $c }
@@ -326,8 +333,6 @@ our multi sub item($item) {
     $item
 }
 
-class Whatever { ... }
-
 our multi sub infix:<...>(Code $lhs, $rhs) {
     my $limit;
     $limit = $rhs if !($rhs ~~ Whatever);
-- 
1.7.2

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

From @coke

On Sun Jul 25 21​:33​:01 2010, felliott wrote​:

Hello,

xx hangs if a non-numeric value appears on the right hand side​:

my @​a = "b" xx "monkey";

my @​c = <a b c>
my @​d = "e" xx @​c;

Attached is a patch which corrects this while still supporting a
Whatever argument like so​:

my @​f = <a b c> Z (1 xx *); # @​f is <a 1 b 1 c 1>

I've added fudged spectests to S03-operators/repeat.t and S05-
transliteration/trans.t (this bug also causes .trans('x' => '') to
hang).

Cheers,
Fitz Elliott

Looks like this patch was already applied, the samples here seem to work. However, I cannot
find this RT or appropriate tests in S03-operators/repeat.t ; assigning to moritz for
spectesting.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in at least one of these files​: t/spec/S03-operators/repeat.t, t/spec/S05-transliteration/trans.t

commit 18fcacf48d808b2d537a70a922bb6620fb4ecfe1
Author​: felliott <felliott@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Wed Jul 28 02​:04​:25 2010 +0000

  document RT # for spectests for RT #​76720
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31851 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S03-operators/repeat.t b/t/spec/S03-operators/repeat.t
index cddaef7..726fdfe 100644
--- a/t/spec/S03-operators/repeat.t
+++ b/t/spec/S03-operators/repeat.t
@@ -76,7 +76,7 @@ is($twin, 'LintillaLintilla', 'operator x= for string repeats correct');
 }
 
 
-# tests for non-number values on rhs of xx
+# tests for non-number values on rhs of xx (RT #76720)
 {
     # make sure repeat numifies rhs, but respects whatever
     my @a = <a b c>;
diff --git a/t/spec/S05-transliteration/trans.t b/t/spec/S05-transliteration/trans.t
index b282268..2f96de4 100644
--- a/t/spec/S05-transliteration/trans.t
+++ b/t/spec/S05-transliteration/trans.t
@@ -111,6 +111,7 @@ is($b.trans('A..H..' => 'a..h__'), 'abcdefghIJKLMNOPQRSTUVWXYZ',
 is($b.trans('..A..H..' => '__a..h__'), 'abcdefghIJKLMNOPQRSTUVWXYZ',
     'leading, trailing ranges interpreted as string');
 
+# added as a consequence of RT #76720
 is("hello".trans("l" => ""), "heo", "can replace with empty string");
 
 # complement, squeeze/squash, delete

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

From @felliott

This should be fixed and the test has been properly marked up, so I am
marking this bug 'resolved'.

Cheers,
Fitz

@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

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

@p6rt p6rt closed this as completed Jul 28, 2010
@p6rt
Copy link
Author

p6rt commented Jul 28, 2010

From @felliott

On Jul 27, 2010, at 9​:56 PM, Will Coleda via RT wrote​:

Looks like this patch was already applied, the samples here seem to work. However, I cannot
find this RT or appropriate tests in S03-operators/repeat.t ; assigning to moritz for
spectesting.

Sorry, I forgot to document the bug number in the test. I'll add it now.

Cheers,
Fitz

@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