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
Comments
From @moritz10:01 < moritz_> rakudo: say <a b c>[0..*-2] |
From @masak<jnthn> rakudo: my @a = 1,2,3,4; say @a[1..*-1] |
From sohtil@gmail.comThis looks like a duplicate of #77104. |
The RT System itself - Status changed from 'new' to 'open' |
From sohtil@gmail.comTicket #77424 looks like a duplicate of this bug. |
The RT System itself - Status changed from 'new' to 'open' |
From @TimbusFixed that for ya |
From @Timbus0001-Added-magical-block-currying-to-ranges-allowing-thin.patchFrom 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
|
From @TimbusOh whoops ignore the last part of the patch, it doesn't do anything. I |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#77104 (status was 'resolved')
Searchable as RT77104$
The text was updated successfully, but these errors were encountered: