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

repeat {} doesn't repeat when it's last item inside a sub called from a loop #5445

Closed
p6rt opened this issue Jul 11, 2016 · 7 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 11, 2016

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

Searchable as RT128596$

@p6rt
Copy link
Author

p6rt commented Jul 11, 2016

From @zoffixznet

The repeat {} block must execute the block at least once, even if the condition is false.

That works fine in a loop​:

  zoffix@​VirtualBox​:~/CPANPRC$ cat test.p6
  for ^2 {
  say "Outside";
  repeat { say "Inside" } while 0;
  }
  zoffix@​VirtualBox​:~/CPANPRC$ perl6 test.p6
  Outside
  Inside
  Outside
  Inside
  zoffix@​VirtualBox​:~/CPANPRC$

And it works fine when in a sub that is called​:

  zoffix@​VirtualBox​:~/CPANPRC$ cat test.p6
  sub foo {
  say "Outside";
  repeat { say "Inside" } while 0;
  };

  foo;
  zoffix@​VirtualBox​:~/CPANPRC$ perl6 test.p6
  Outside
  Inside
  zoffix@​VirtualBox​:~/CPANPRC$

But if we call that sub in a loop, repeat no longer gets called​:

  zoffix@​VirtualBox​:~/CPANPRC$ cat test.p6
  sub foo {
  say "Outside";
  repeat { say "Inside" } while 0;
  }

  foo for ^2;
  zoffix@​VirtualBox​:~/CPANPRC$ perl6 test.p6
  Outside
  Outside
  zoffix@​VirtualBox​:~/CPANPRC$

See also https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127563#ticket-history which may or may not be related

--
Cheers,
ZZ | https://twitter.com/zoffix

@p6rt
Copy link
Author

p6rt commented Jul 11, 2016

From @zoffixznet

zoffix@​VirtualBox​:~/CPANPRC$ perl6 -v
This is Rakudo version 2016.06-154-g55c359e built on MoarVM version 2016.06-9-g8fc21d5
implementing Perl 6.c.

@p6rt
Copy link
Author

p6rt commented Jul 11, 2016

From @zoffixznet

'been a long day and I forgot one key point. It starts to work fine if we don't make it the last item in the sub​:

zoffix@​VirtualBox​:~/CPANPRC$ cat test.p6
sub foo {
  say "Outside";
  repeat { say "Inside" } while 0;
  Nil;
}

foo for ^2;
zoffix@​VirtualBox​:~/CPANPRC$ perl6 test.p6
Outside
Inside
Outside
Inside
zoffix@​VirtualBox​:~/CPANPRC$

--
Cheers,
ZZ | https://twitter.com/zoffix

@p6rt
Copy link
Author

p6rt commented Jul 12, 2016

From @zoffixznet

Fudged tests added in Raku/roast@9236d81b3e

@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

From @TimToady

The repeat and loop constructs were not properly sinking themselves at statementlist level.

Fixed in 589061eac14f2847e2c4b401d2ff2eb30c62675e

Untodo'd existing test.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

From @TimToady

The repeat and loop constructs were not properly sinking themselves at statementlist level.

Fixed in 589061eac14f2847e2c4b401d2ff2eb30c62675e

Untodo'd existing test.

@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

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

@p6rt p6rt closed this as completed Aug 6, 2016
@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