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

Fix Seq.perl to not say Seq.new(). Interim fix for Iterator.perl to fix infinite loops #1708

Closed
p6rt opened this issue Apr 20, 2010 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 20, 2010

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

Searchable as RT74526$

@p6rt
Copy link
Author

p6rt commented Apr 20, 2010

From quester.pm@gmail.com

Hello,

I noticed finanalyst having problems with Rakudo on #perl6 on 2010-04-20​:

05​:36 finanalyst alpha​: my @​a = 1,2,3,4; my %h; %h{@​a[0]} = @​a[1 ..^ +@​a];
%h.perl.say
05​:36 p6eval alpha 30e0ed​: OUTPUT«{"1" => [2, 3, 4]}␤»
05​:36 finanalyst rakudo​: my @​a = 1,2,3,4; my %h; %h{@​a[0]} = @​a[1 ..^ +@​a];
%h.perl.say
05​:36 p6eval rakudo b05155​: OUTPUT«{"1" => Seq.new()}␤»

The fix was just to copy the perl method from Array.pm to Seq.pm (and change
the output from square brackets to parentheses.)

I also remembered how many times I have been annoyed with Rakudo going into
an infinite loop when trying to cope with Iterator.perl. For example,

my $a=(1,1,* + * ... *); $a.perl.say;

There was some discussion around 10​:54 UTC 2010-04-20 on #perl6 about the
Iterator.perl case, most of which doesn't lend itself to implementation
without drastic work on the compiler (the ability to serialize code and have
iterators be able to memoize and unget their values.) To make life somewhat
more tolerable before utopia arrives, I took one of TimToady's many
suggestions and cut the output short at forty entries.

I include some comments in Iterator.pm to indicate that the code is a
placeholder for future, better code; you might want to edit that for style.

Please let me know if you have any questions or suggestions.

Best regards,
Ira Kevin Byerly
quester_ on #perl6
quester on perlmonks
quester.pm@​gmail.com

@p6rt
Copy link
Author

p6rt commented Apr 20, 2010

From quester.pm@gmail.com

0001-Fix-Seq.perl-to-not-say-Seq.new-.-Interim-fix-for-It.patch
From 54ab1068bff26928c2920598a8d53ac1cab8ef21 Mon Sep 17 00:00:00 2001
From: quester <quester.pm@gmail.com>
Date: Tue, 20 Apr 2010 00:20:12 -1000
Subject: [PATCH] Fix Seq.perl to not say Seq.new().  Interim fix for Iterator.perl infinite loops.

---
 src/core/Iterator.pm |   13 +++++++++++--
 src/core/Seq.pm      |    4 ++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/core/Iterator.pm b/src/core/Iterator.pm
index b4c4d77..6545dd6 100644
--- a/src/core/Iterator.pm
+++ b/src/core/Iterator.pm
@@ -1,6 +1,15 @@
 augment class Iterator {
-    multi method perl() {
-        $.eager.perl;
+    multi method perl(:$limit = 40) {
+        # Doing this right is probably beyond mortal dwimmery,
+        # and even in simple cases it needs the ability to
+        # serialize code to have any hope of producing
+        # output like (1, 1, * + * ... *)
+        # rather than (1, 1, 2, 3, 5, {???} ... ???).
+        # Try to do something useful for debugging, for now.
+        my @a = self.batch($limit);
+        my $and_more = '';
+        $and_more = ', {???} ... ???' if @a == $limit;
+        '(' ~ @a.map({ $^a.perl }).join(', ') ~ $and_more ~ ')';
     }
 
     multi method elems() {
diff --git a/src/core/Seq.pm b/src/core/Seq.pm
index a7b95c2..b3459ff 100644
--- a/src/core/Seq.pm
+++ b/src/core/Seq.pm
@@ -88,6 +88,10 @@ augment class Seq {
     multi method fmt($format = '%s', $seperator = ' ') {
         self.map({ .fmt($format)}).join($seperator);
     }
+
+    method perl() {
+        '(' ~ self.map({ $^a.perl }).join(', ') ~ ')';
+    }
 }
 
 multi sub sort (@x, :&by = &infix:<cmp>) { @x.sort(&by) }
-- 
1.6.6.1

@p6rt
Copy link
Author

p6rt commented Apr 20, 2010

From @quester

This is a fix for RT #​74518 "[BUG] rakudo regression .perl". Sorry, I
didn't notice this bug report until after I submitted the patch. - quester

@p6rt
Copy link
Author

p6rt commented Apr 22, 2010

From @moritz

Applied by colomon++ as d952fc4b1d052c0b2f6cce2ae2f26ab813776a61

@p6rt
Copy link
Author

p6rt commented Apr 22, 2010

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

@p6rt p6rt closed this as completed Apr 22, 2010
@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