# New Ticket Created by  Moritz Lenz 
# Please include the string:  [perl #66826]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=66826 >


Attached patch implements the eager version of infix:<...> (the series
operator). It makes rakudo fail like this:

$ perl6 -e '1...{()}'
Null PMC access in find_method()
current instr.: '' pc 80114 (src/gen_setting.pir:0)
(src/gen_setting.pm:1200)
called from Sub '_block18' pc -1 ((unknown file):-1)

However when I apply only the patch to grammar-oper.pg and put the
definition of src/setting/Operators.pm into a script and use the
operator after that, it works just fine.

I don't know yet how general this problem is, but if it appears in all
cases of operators defined in the setting, it will severely limit its
usefulness.

Cheers,
Moritz
From f232e8ea7f16d46eb284946483a530708bf905b6 Mon Sep 17 00:00:00 2001
From: Moritz Lenz <mor...@faui2k3.org>
Date: Sun, 21 Jun 2009 21:17:33 +0200
Subject: [PATCH] implement (non-lazy) series operator

---
 build/Makefile.in          |    1 +
 src/parser/grammar-oper.pg |    4 ++++
 src/setting/Operators.pm   |   25 +++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 0 deletions(-)
 create mode 100644 src/setting/Operators.pm

diff --git a/build/Makefile.in b/build/Makefile.in
index 2ec0b9a..9365d2f 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -122,6 +122,7 @@ SETTING = \
   src/setting/Match.pm \
   src/setting/Num.pm \
   src/setting/Object.pm \
+  src/setting/Operators.pm \
   src/setting/Pair.pm \
   src/setting/Range.pm \
   src/setting/Temporal.pm \
diff --git a/src/parser/grammar-oper.pg b/src/parser/grammar-oper.pg
index 4866f84..7343540 100644
--- a/src/parser/grammar-oper.pg
+++ b/src/parser/grammar-oper.pg
@@ -161,6 +161,10 @@ proto infix:«p5=>» is equiv(infix:<,>) is subname('infix:,') { ... }
 ## list infix
 proto infix:<X> is precedence('f=')
     is assoc('list')
+   { ... }
+# needs to come before the others because of missing LTM
+proto infix:<...> is equiv(infix:<X>)
+    is assoc('list')
     { ... }
 proto infix:<X,X> is equiv(infix:<X>)
     is assoc('list')
diff --git a/src/setting/Operators.pm b/src/setting/Operators.pm
new file mode 100644
index 0000000..d6b9e06
--- /dev/null
+++ b/src/setting/Operators.pm
@@ -0,0 +1,25 @@
+# operators defined in the setting
+
+multi sub infix:<...> (@lhs, Code $generator) {
+    my $c = $generator.count;
+    if $c > @lhs {
+        fail 'the closure wants more parameters than given on the LHS';
+    }
+    my @result = @lhs;
+    my @r;
+    # XXX work around http://rt.perl.org/rt3/Ticket/Display.html?id=66824
+    # this is a bit ugly.. since @a[1..1] returns a single item and not 
+    # an array, |@result[$one-item-range] throws the error
+    # "argument doesn't array"
+    while @r = $generator(|@(@result[*-$c..*-1])) {
+        @result.push: @r;
+    }
+    return @result;
+}
+
+my @a = 1, 2 ... { $_ > 3 ?? () !! $_+1};
+say @a.perl;
+
+
+
+# vim: ft=perl6
-- 
1.5.6.5

Reply via email to