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

Bug in recursion and loops #2555

Closed
p6rt opened this issue Nov 10, 2011 · 5 comments
Closed

Bug in recursion and loops #2555

p6rt opened this issue Nov 10, 2011 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Nov 10, 2011

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

Searchable as RT103332$

@p6rt
Copy link
Author

p6rt commented Nov 10, 2011

From mark@kli.org

 

 
 
 
  Variables seem to wind up with the wrong values inside loops in
  recursive functions.
 

  Code​:
 

 
  my $counter=0;
sub recur(Int $x) {     my $h;     $h="h" ~ $counter;     $counter++;     my @​k=(1,6);     if ($x>0) { recur($x-1);     }     for @​k { say $_ ~ " and h is $h";     }     say "h is $h"; }
recur(3);

Results​:
  Expected output, and received from earlier perl6 (This is Rakudo Perl 6, version 2011.06 built on parrot 3.5.0 RELEASE_3_5_0)​:

1 and h is h3
6 and h is h3
h is h3
1 and h is h2
6 and h is h2
h is h2
1 and h is h1
6 and h is h1
h is h1
1 and h is h0
6 and h is h0
h is h0
Output received from later rakudo (This is perl6 version
2011.10-98-g1985138 built on parrot 3.9.0 revision
RELEASE_3_9_0-51-g65e6ab7)​:

1 and h is h3
6 and h is h3
h is h3
1 and h is h3
6 and h is h3
h is h2
1 and h is h3
6 and h is h3
h is h1
1 and h is h3
6 and h is h3
h is h0
  ======

~mark

 

 
 

@p6rt
Copy link
Author

p6rt commented Nov 10, 2011

From @moritz

Test added to S04-statements/for.t.

@p6rt
Copy link
Author

p6rt commented Nov 10, 2011

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

@p6rt
Copy link
Author

p6rt commented Nov 15, 2011

From @jnthn

On Thu Nov 10 07​:06​:41 2011, mark@​kli.org wrote​:

Variables seem to wind up with the wrong values inside loops in
recursive
functions.

Code​:

my $counter=0;sub recur(Int $x) {����my $h;����$h="h" ~ $counter;
$counter++;����my @​k=(1,6);����if ($x>0) { recur($x-1);����}
for @​k { say $_ ~ " and h is $h";����}����say "h is
$h";}recur(3);======
Results​:

Expected output, and received from earlier perl6 (This is Rakudo Perl
6, version 2011.06 built on parrot 3.5.0 RELEASE_3_5_0)​:

1 and h is h3
6 and h is h3
h is h3
1 and h is h2
6 and h is h2
h is h2
1 and h is h1
6 and h is h1
h is h1
1 and h is h0
6 and h is h0
h is h0

Output received from later rakudo (This is perl6 version
2011.10-98-g1985138 built on parrot 3.9.0 revision
RELEASE_3_9_0-51-g65e6ab7)​:

1 and h is h3
6 and h is h3
h is h3
1 and h is h3
6 and h is h3
h is h2
1 and h is h3
6 and h is h3
h is h1
1 and h is h3
6 and h is h3
h is h0

  ======

Thanks for reporting. This issue has been fixed, and a test has been
added. Resolving ticket.

Thanks,

/jnthn

@p6rt
Copy link
Author

p6rt commented Nov 15, 2011

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

@p6rt p6rt closed this as completed Nov 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant