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

Rakudo doesn't like WhateverCode ranges in postcircumfix:<[ ]> #2039

Closed
p6rt opened this issue Aug 9, 2010 · 10 comments
Closed

Rakudo doesn't like WhateverCode ranges in postcircumfix:<[ ]> #2039

p6rt opened this issue Aug 9, 2010 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Aug 9, 2010

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

Searchable as RT77104$

@p6rt
Copy link
Author

p6rt commented Aug 9, 2010

From @moritz

10​:01 < moritz_> rakudo​: say <a b c>[0..*-2]
10​:01 <+p6eval> rakudo 38f9f1​: OUTPUT«Method 'Num' not found for
invocant of
  class 'WhateverCode'␤ in 'Cool​::Numeric' at line
  1757​:CORE.setting␤ in 'Cool​::Numeric' at line
  1758​:CORE.setting␤ in 'infix​:<==>' at line
6581​:CORE.setting␤
  in 'Range​::iterator' at line 4557​:CORE.setting␤ in
  'Any​::postcircumfix​:<[

@p6rt
Copy link
Author

p6rt commented Aug 24, 2010

From @masak

<jnthn> rakudo​: my @​a = 1,2,3,4; say @​a[1..*-1]
<p6eval> rakudo 82c9e9​: OUTPUT«Method 'Num' not found for invocant of
class 'WhateverCode'␤ in 'Cool​::Numeric' at line 1745​:CORE.setting␤
in 'Cool​::Numeric' at line 1746​:CORE.setting␤ in 'Range​::new' at line
4676​:CORE.setting␤ in 'infix​:<..>' at line 4739​:CORE.setting␤ [...]
<jnthn> ew er
<masak> :/
<jnthn> Why on earth does Cool​::Numeric show up twice in the backtrace?
<masak> multi delegation?
* masak submits rakudobug for that, too

@p6rt
Copy link
Author

p6rt commented Aug 25, 2010

From sohtil@gmail.com

This looks like a duplicate of #​77104.

@p6rt
Copy link
Author

p6rt commented Aug 25, 2010

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

@p6rt
Copy link
Author

p6rt commented Aug 25, 2010

From sohtil@gmail.com

Ticket #​77424 looks like a duplicate of this bug.

@p6rt
Copy link
Author

p6rt commented Aug 25, 2010

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

@p6rt
Copy link
Author

p6rt commented Aug 25, 2010

From @Timbus

Fixed that for ya

@p6rt
Copy link
Author

p6rt commented Aug 25, 2010

From @Timbus

0001-Added-magical-block-currying-to-ranges-allowing-thin.patch
From ff71a7999817c8d4a0eb51eb8fd13f16fbb544ed Mon Sep 17 00:00:00 2001
From: Jarrod <gigantic.midget@gmail.com>
Date: Thu, 26 Aug 2010 00:22:02 +1000
Subject: [PATCH] Added magical block currying to ranges, allowing things like @array[1..*-1] and @array[*-5..*-1] to work.

---
 src/core/Any-list.pm |    2 +-
 src/core/Range.pm    |   32 +++++++++++++++++++++++++++-----
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/core/Any-list.pm b/src/core/Any-list.pm
index 947beb5..da8dbdd 100644
--- a/src/core/Any-list.pm
+++ b/src/core/Any-list.pm
@@ -292,7 +292,7 @@ augment class Any {
         self[0..(self.elems-1)]
     }
 
-    our multi method postcircumfix:<[ ]>(&block) { self[&block(self.elems)]; }
+    our multi method postcircumfix:<[ ]>(&block) { self[&block( |(self.elems xx &block.arity) )]; }
 
     our multi method postcircumfix:<[ ]>(@pos) {
         my $result = pir::new__ps('ResizablePMCArray');
diff --git a/src/core/Range.pm b/src/core/Range.pm
index 93d97f9..fef352b 100644
--- a/src/core/Range.pm
+++ b/src/core/Range.pm
@@ -36,20 +36,42 @@ class Range is Iterable does Positional {
         !! nextsame;
     }
 
+    multi method new($min, Code $max,
+                     Bool :$excludes_min = Bool::False,
+                     Bool :$excludes_max = Bool::False) {
+        -> *@args { $min..$max(|@args) } does role { method arity { $max.arity } };
+    }
+
+    multi method new(Code $min, $max,
+                     Bool :$excludes_min = Bool::False,
+                     Bool :$excludes_max = Bool::False) {
+        -> *@args { $min(|@args)..$max } does role { method arity { $min.arity } };
+    }
+
+    multi method new(Code $min, Code $max,
+                     Bool :$excludes_min = Bool::False,
+                     Bool :$excludes_max = Bool::False) {
+        -> *@args is copy {
+            my @amin;
+            @amin.push(@args.shift) for 1..$min.arity;
+            $min(|@amin)..$max(|@args);
+        } does role { method arity { $min.arity + $max.arity } };
+    }
+
     multi method bounds() { ($.min, $.max) }
     multi method from() { $.min; }
     multi method to() { $.max; }
 
     multi method iterator() {
-        RangeIter.new(:value($!excludes_min ?? $!min.succ !! $!min), 
+        RangeIter.new(:value($!excludes_min ?? $!min.succ !! $!min),
                       :$!max, :$!excludes_max);
     }
 
     our Str multi method perl() {
-        ( $.min.perl, 
-          ('^' if $.excludes_min), 
-          '..', 
-          ('^' if $.excludes_max), 
+        ( $.min.perl,
+          ('^' if $.excludes_min),
+          '..',
+          ('^' if $.excludes_max),
           $.max.perl
         ).join('');
     }
-- 
1.7.0.4

@p6rt
Copy link
Author

p6rt commented Aug 25, 2010

From @Timbus

Oh whoops ignore the last part of the patch, it doesn't do anything. I
started deleting trailing whitespaces from my changes because git diff
makes a big deal about them, and then I just kept going ;/

@p6rt
Copy link
Author

p6rt commented Dec 18, 2010

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

@p6rt p6rt closed this as completed Dec 18, 2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant