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

Scoping issue in list comprehension with gather/take-rw in it in Rakudo #2685

Closed
p6rt opened this issue Mar 24, 2012 · 7 comments
Closed

Scoping issue in list comprehension with gather/take-rw in it in Rakudo #2685

p6rt opened this issue Mar 24, 2012 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 24, 2012

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

Searchable as RT111962$

@p6rt
Copy link
Author

p6rt commented Mar 24, 2012

From @masak

<TimToady> masak​: two bug reports for the price of one; rakudo and
niecza both fail this test for different reasons​:
https://gist.github.com/2185853
<TimToady> niecza because it has not take-rw (though take works
because it doesn't properly decontainerize)
<TimToady> rakudo because of the scoping issue in the list
comprehension (pretty much any refactoring of the loop and conditional
works)
<masak> TimToady​: I'm wondering if you haven't just re-discovered
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=109322

TimToady's gist, reproduced here​:

use Test;

{
  my @​grid = [ Bool.pick xx 5 ] xx 5;
  my @​neigh = [ ] xx 5;
  for ^5 X ^5 -> $i, $j {
  @​neigh[$i][$j] = gather take-rw @​grid[$i + .[0]][$j + .[1]]
  if 0 <= $i + .[0] < 5 and 0 <= $j + .[1] < 5
  for [-1,-1],[+0,-1],[+1,-1],
  [-1,+0],( ),[+1,+0],
  [-1,+1],[+0,+1],[+1,+1];
  }
  ok @​grid[1][1] =​:= @​neigh[2][2][0], "Neighbor is same object as in grid";
  ok @​neigh[1][1].elems == 8, "There are eight neighbors";
}

@p6rt
Copy link
Author

p6rt commented May 30, 2012

From @diakopter

On Sat Mar 24 14​:28​:16 2012, masak wrote​:

<TimToady> masak​: two bug reports for the price of one; rakudo and
niecza both fail this test for different reasons​:
https://gist.github.com/2185853
<TimToady> niecza because it has not take-rw (though take works
because it doesn't properly decontainerize)
<TimToady> rakudo because of the scoping issue in the list
comprehension (pretty much any refactoring of the loop and conditional
works)
<masak> TimToady​: I'm wondering if you haven't just re-discovered
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=109322

TimToady's gist, reproduced here​:

use Test;

{
my @​grid = [ Bool.pick xx 5 ] xx 5;
my @​neigh = [ ] xx 5;
for ^5 X ^5 -> $i, $j {
@​neigh[$i][$j] = gather take-rw @​grid[$i + .[0]][$j + .[1]]
if 0 <= $i + .[0] < 5 and 0 <= $j + .[1] < 5
for [-1,-1],[+0,-1],[+1,-1],
[-1,+0],( ),[+1,+0],
[-1,+1],[+0,+1],[+1,+1];
}
ok @​grid[1][1] =​:= @​neigh[2][2][0], "Neighbor is same object as in
grid";
ok @​neigh[1][1].elems == 8, "There are eight neighbors";
}

I'm pretty sure this one works now (in both niecza and rakudo?).

@p6rt
Copy link
Author

p6rt commented May 30, 2012

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

@p6rt
Copy link
Author

p6rt commented May 9, 2014

From @lizmat

[15​:12​:04] <grondilu> so List.permutations and List.combinations are broken. Seems due to List[@​a] not working. Is someone looking at that?
[15​:13​:09] <lizmat> grondilu​: could you provide a test case?
[15​:13​:42] <grondilu> r​: .say for <a b c>.permutations; # like this?
[15​:13​:47] <+camelia> rakudo-moar 362f3f​: OUTPUT«Cannot call 'postcircumfix​:<[ ]>'; none of these signatures match​:␤​:(Any \SELF, int $pos)␤​:(Any \SELF, int $pos, \assignee)␤​:(Any \SELF, int $pos, :BIND($BIND)!)␤​:(Any \SELF, int $pos, Any :SINK($SINK)!, *%other)␤​:(Any \SELF, int $pos, Any :delet…»
[15​:13​:47] <+camelia> ..rakudo-{parrot,jvm} 362f3f​: OUTPUT«a b c␤a c b␤b a c␤b c a␤c a b␤c b a␤»
[15​:14​:09] <grondilu> oh I hadn't realised it was only on moar
...
[15​:16​:08] <lizmat> "gather take [self[@​$_]] for permutations self.elems;"
[15​:16​:15] <lizmat> seems to be the line where it does
[15​:16​:17] <lizmat> *dies
...
[15​:32​:05] <+dalek> rakudo/nom​: 55bf027 | (Elizabeth Mattijsen)++ | src/core/List.pm​:
[15​:32​:05] <+dalek> rakudo/nom​: Temporary fix to get List.permutations to work
[15​:32​:05] <+dalek> rakudo/nom​: review​: rakudo/rakudo@55bf02751f
...
[15​:35​:45] <jnthn> If you use the block form of gather instead, does it fix things?
[15​:36​:36] <lizmat> testing...
[15​:38​:36] <lizmat> that seems to fix it, indeed
...
[15​:40​:13] <lizmat> indeed, it does not seem to be the recursion, but the blocklessness of the gather take in permutations
...
[15​:42​:33] <jnthn> lizmat​: OK, if that fixes it, then that's the workaround to go for, and then let's ticket this as a blockless gather bug on Moar
...
[15​:44​:36] <lizmat> jnthn​: shall I do the same for jvm/parrot, so we don't special case Moar, or should I keep it as a reminder ?
[15​:45​:15] <jnthn> lizmat​: Oh, workaround can be just doen for all platforms
[15​:45​:22] <jnthn> lizmat​: I mean ticket can just be marked as moar only

@p6rt
Copy link
Author

p6rt commented Apr 28, 2015

From @jnthn

On Sat Mar 24 14​:28​:16 2012, masak wrote​:

<TimToady> masak​: two bug reports for the price of one; rakudo and
niecza both fail this test for different reasons​:
https://gist.github.com/2185853
<TimToady> niecza because it has not take-rw (though take works
because it doesn't properly decontainerize)
<TimToady> rakudo because of the scoping issue in the list
comprehension (pretty much any refactoring of the loop and conditional
works)
<masak> TimToady​: I'm wondering if you haven't just re-discovered
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=109322

TimToady's gist, reproduced here​:

use Test;

{
my @​grid = [ Bool.pick xx 5 ] xx 5;
my @​neigh = [ ] xx 5;
for ^5 X ^5 -> $i, $j {
@​neigh[$i][$j] = gather take-rw @​grid[$i + .[0]][$j + .[1]]
if 0 <= $i + .[0] < 5 and 0 <= $j + .[1] < 5
for [-1,-1],[+0,-1],[+1,-1],
[-1,+0],( ),[+1,+0],
[-1,+1],[+0,+1],[+1,+1];
}
ok @​grid[1][1] =​:= @​neigh[2][2][0], "Neighbor is same object as in
grid";
ok @​neigh[1][1].elems == 8, "There are eight neighbors";
}

Fixed, and added this (with one minor update for list flattening changes) as a test to S04-statements/gather.t.

@p6rt p6rt closed this as completed Apr 28, 2015
@p6rt
Copy link
Author

p6rt commented Apr 28, 2015

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

@p6rt
Copy link
Author

p6rt commented Nov 15, 2015

From @zhuomingliang

Hello,

It seems it is not fixed, because the following patch didn't work.

Inline Patch
diff --git a/src/core/List.pm b/src/core/List.pm
index 72fcbd7..776e8dd 100644
--- a/src/core/List.pm
+++ b/src/core/List.pm
@@ -878,8 +878,7 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
 
     proto method permutations(|) is nodal {*}
     multi method permutations() is nodal {
-        # need block on Moar because of RT#121830
-        permutations(self.elems).map: { self[@$_] }
+        permutations(self.elems).map: self[@$_]
     }
 
     method join($separator = '') is nodal {
(END)

@p6rt p6rt added the Bug 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