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
Sequence operator supports limit function with arity > 1 #2373
Comments
From dwhipp@google.comAttached patches add tests and implementation for sequence operator with 1, */2 ... abs(*-*) < 0.01; ## convergence: 8 values |
From dwhipp@google.com0001-tests-of-sequence-operator-with-limit-function-havin.patchFrom 608d6c1dc96b81e0537d670d9949451c227f5708 Mon Sep 17 00:00:00 2001
From: Dave Whipp <dwhipp@google.com>
Date: Thu, 17 Feb 2011 12:08:45 -0800
Subject: [PATCH] tests of sequence operator with limit function having arity > 1
---
S03-sequence/limit-arity-2-or-more.t | 37 ++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
create mode 100644 S03-sequence/limit-arity-2-or-more.t
diff --git a/S03-sequence/limit-arity-2-or-more.t b/S03-sequence/limit-arity-2-or-more.t
new file mode 100644
index 0000000..5524ea8
--- /dev/null
+++ b/S03-sequence/limit-arity-2-or-more.t
@@ -0,0 +1,37 @@
+use v6;
+use Test;
+
+# L<S03/List infix precedence/"the sequence operator">
+
+plan 8;
+
+# sequence with a limit function of arity 2
+
+is (8,*/2 ... abs(*-*) < 2).join(', '), '8, 4, 2, 1', 'arity-2 convergence limit';
+is (8,*/2 ...^ abs(*-*) < 2).join(', '), '8, 4, 2', 'arity-2 excluded convergence limit';
+
+# sequence with a limit function of arity 3
+
+{
+ my $i = -5;
+ my @seq = { ++$i; $i**3-9*$i } ... { ($^a-$^b) > ($^b-$^c) };
+ is @seq.join(', '), '-28, 0, 10, 8, 0, -8, -10', 'arity-3 curvature limit';
+}
+
+{
+ my $i = -5;
+ my @seq = { ++$i; $i**3-9*$i } ...^ { ($^a-$^b) > ($^b-$^c) };
+ is @seq.join(', '), '-28, 0, 10, 8, 0, -8', 'arity-3 excluded curvature limit';
+}
+
+# limit functions that limit sequence exactly at arity limit
+
+is (2, 1, 0.5 ... abs(*-*) < 2).join(', '), '2, 1', 'ASAP arity-2 convergence limit';
+is (2, 1, 0.5 ...^ abs(*-*) < 2).join(', '), '2', 'ASAP arity-2 excluded convergence limit';
+
+# limit function that accepts any number of args
+
+is (1 ... { @_ eq "1 2 3" }).join(', '), '1, 2, 3', 'arity-Inf limit';
+is (1 ...^ { @_ eq "1 2 3" }).join(', '), '1, 2', 'arity-Inf excluded limit';
+
+done;
--
1.7.3.1
|
From dwhipp@google.com0001-Sequence-operator-supports-limit-functions-with-arit.patchFrom de547c7c44810e1cd8d03c023cc380498bff6301 Mon Sep 17 00:00:00 2001
From: Dave Whipp <dwhipp@google.com>
Date: Thu, 17 Feb 2011 12:07:27 -0800
Subject: [PATCH] Sequence operator supports limit functions with arity > 1
---
src/core/operators.pm | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/core/operators.pm b/src/core/operators.pm
index c92e9f2..074db9f 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -401,16 +401,30 @@ our sub _HELPER_generate-series(@lhs, $rhs , :$exclude-limit) {
my $limit = ($rhs ~~ Whatever ?? Any !! $rhs);
return infinite-series(@lhs , $limit) if $rhs ~~ Whatever; #shortcut infinite series so we avoid the comparisions
- fail ('Limit arity cannot be larger than 1') if $limit ~~ Code && $limit.count > 1;
+ #fail ('Limit arity cannot be larger than 1') if $limit ~~ Code && $limit.count > 1;
my $series = infinite-series(@lhs , $limit);
+
gather {
- while $series {
- my $val = $series.shift();
- if $val ~~ $limit {
- take $val unless $exclude-limit ;
- last ;
- };
- take $val;
+ if $limit ~~ Code && $limit.count > 1 {
+ my @limit-args;
+ while $series {
+ @limit-args.shift if @limit-args == $limit.count;
+ my $val = $series.shift;
+ @limit-args.push($val);
+ my $done = @limit-args >= $limit.arity && $limit(|@limit-args);
+ take $val unless $done && $exclude-limit;
+ last if $done;
+ }
+ }
+ else {
+ while $series {
+ my $val = $series.shift();
+ if $val ~~ $limit {
+ take $val unless $exclude-limit ;
+ last ;
+ };
+ take $val;
+ }
}
}
}
--
1.7.3.1
|
From dwhipp@google.comOne extra patch for this change: an error if the limit-function is a multi On Thu, Feb 17, 2011 at 2:35 PM, perl6 via RT
|
From dwhipp@google.com0001-add-error-for-use-of-Multi-as-sequence-limit.patchFrom 2312784b7a147bf2613b3e95f5ae37ed8dbbccaa Mon Sep 17 00:00:00 2001
From: Dave Whipp <dwhipp@google.com>
Date: Fri, 25 Feb 2011 09:27:03 -0800
Subject: [PATCH] add error for use of Multi as sequence limit
---
src/core/operators.pm | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/core/operators.pm b/src/core/operators.pm
index 074db9f..980a86e 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -401,7 +401,7 @@ our sub _HELPER_generate-series(@lhs, $rhs , :$exclude-limit) {
my $limit = ($rhs ~~ Whatever ?? Any !! $rhs);
return infinite-series(@lhs , $limit) if $rhs ~~ Whatever; #shortcut infinite series so we avoid the comparisions
- #fail ('Limit arity cannot be larger than 1') if $limit ~~ Code && $limit.count > 1;
+ die 'Sequence limit cannot be a multi-sub or multi-method' if $limit ~~ Multi;
my $series = infinite-series(@lhs , $limit);
gather {
--
1.7.3.1
|
From @moritzOn Thu Feb 17 14:35:14 2011, dwhipp@google.com wrote:
Thank you for your patches, I've applied all three. If you tell me your github ID I can also give you commit access to roast Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'resolved' |
From dwhipp@google.comThank you. My github ID is "dwhipp". Dave. On Fri, Feb 25, 2011 at 11:56 AM, Moritz Lenz via RT <
|
Migrated from rt.perl.org#84362 (status was 'resolved')
Searchable as RT84362$
The text was updated successfully, but these errors were encountered: