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

Calling an anonymous sub in a for loop makes the for loop not run in Rakudo #2101

Closed
p6rt opened this issue Aug 26, 2010 · 5 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 26, 2010

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

Searchable as RT77460$

@p6rt
Copy link
Author

p6rt commented Aug 26, 2010

From @masak

<masak> rakudo​: my @​a = 1; for 1..10 { my $last = @​a[*-1]; say $last;
push @​a, (sub ($s) { $s + 1 })($last) }; say @​a.perl
<p6eval> rakudo df38ac​: OUTPUT«[1]␤»
<masak> could somebody confirm to me that this is not expected behaviour?
<masak> I expect [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
<sorear> what's with the say $last?
<masak> it doesn't print.
<masak> it's as if the loop doesn't run.
<masak> rakudo​: my @​a = 1; for 1..10 { my $last = @​a[*-1]; say $last;
push @​a, $last + 1 }; say @​a.perl
<p6eval> rakudo df38ac​: OUTPUT«1␤2␤3␤4␤5␤6␤7␤8␤9␤10␤[1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11]␤»
* masak submits rakudobug

@p6rt
Copy link
Author

p6rt commented Jan 11, 2012

From @coke

On Thu Aug 26 16​:32​:05 2010, masak wrote​:

<masak> rakudo​: my @​a = 1; for 1..10 { my $last = @​a[*-1]; say $last;
push @​a, (sub ($s) { $s + 1 })($last) }; say @​a.perl
<p6eval> rakudo df38ac​: OUTPUT«[1]␤»
<masak> could somebody confirm to me that this is not expected
behaviour?
<masak> I expect [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
<sorear> what's with the say $last?
<masak> it doesn't print.
<masak> it's as if the loop doesn't run.
<masak> rakudo​: my @​a = 1; for 1..10 { my $last = @​a[*-1]; say $last;
push @​a, $last + 1 }; say @​a.perl
<p6eval> rakudo df38ac​: OUTPUT«1␤2␤3␤4␤5␤6␤7␤8␤9␤10␤[1, 2, 3,
4, 5, 6,
7, 8, 9, 10, 11]␤»
* masak submits rakudobug

This works now​:

10​:24 < [Coke]> rakudo​: my @​a = 1; for 1..10 { my $last = @​a[*-1]; say
$last;
  push @​a, (sub ($s) { $s + 1 })($last) }; say @​a.perl
10​:24 <+p6eval> rakudo 38165a​:
OUTPUT«1␤2␤3␤4␤5␤6␤7␤8␤9␤10␤Array.new(1, 2, 3,
  4, 5, 6, 7, 8, 9, 10, 11)␤»

Needs tests.
--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Jan 11, 2012

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

@p6rt
Copy link
Author

p6rt commented Feb 28, 2013

From @timo

added a slightly modified version of that code to roast in 7bcdd2b.

@p6rt
Copy link
Author

p6rt commented Feb 28, 2013

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

@p6rt p6rt closed this as completed Feb 28, 2013
@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