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

can not pop state anonymous array with repetition operator #3132

Open
p6rt opened this issue May 12, 2013 · 3 comments
Open

can not pop state anonymous array with repetition operator #3132

p6rt opened this issue May 12, 2013 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 12, 2013

Migrated from rt.perl.org#117975 (status was 'open')

Searchable as RT117975$

@p6rt
Copy link
Author

p6rt commented May 12, 2013

From @grondilu

This is perl6 version 2013.04-57-gb1695cf built on parrot 5.2.0
revision RELEASE_5_2_0

my @​a = ^3;
say (state@​ = @​a).pop xx 2;
say @​a;

Returns​:
OUTPUT«Element popped from empty list␤ in method Str at
  src/gen/CORE.setting​:10021␤ in method Str at src/gen/CORE.setting​:876␤ in method Stringy at
  src/gen/CORE.setting​:885␤ in method join at src/gen/CORE.setting​:1375␤ in method Str at
  src/gen/CORE.setting​:5969␤ in …

Expected​:
2 1
0 1 2

@p6rt
Copy link
Author

p6rt commented Feb 11, 2016

From @skids

The array does not have to be anonymous​:

$ perl6 -e 'my @​a = 1,2,3; say (state @​b = @​a).pop xx 2; say @​a;'
Cannot pop from an empty Array
  in block <unit> at -e line 1

Actually thrown at​:
  in block <unit> at -e line 1

Other fun things that either work or do not​:

$ perl6 -e 'my @​a = 1,2,3; say (state @​b = @​a).pop for 1,1; say @​a;'
Cannot pop from an empty Array
  in block <unit> at -e line 1

Actually thrown at​:
  in block <unit> at -e line 1
$ perl6 -e 'my @​a = 1,2,3; for 1,1 { say (state @​b = @​a).pop }; say @​a;'
3
2
[1 2 3]

$ perl6 -e 'my @​a = 1,2,3; (say (state @​b = @​a).pop) for 1,1; say @​a;'
Cannot pop from an empty Array
  in block <unit> at -e line 1

Actually thrown at​:
  in block <unit> at -e line 1

$ perl6 -e 'my @​a = 1,2,3; my @​b; say ((once @​b = @​a) // @​b).pop xx 2; say @​a;'
Cannot pop from an empty Array
  in block <unit> at -e line 1

Actually thrown at​:
  in block <unit> at -e line 1

$ perl6 -e 'my @​a = 1,2,3; my @​b; (say ((once @​b = @​a) // @​b).pop) for 1,1; say @​a;'
Cannot pop from an empty Array
  in block <unit> at -e line 1

Actually thrown at​:
  in block <unit> at -e line 1

$ perl6 -e 'my @​a = 1,2,3; my @​b; for 1,1 { say ((once @​b = @​a) // @​b).pop }; say @​a;'
3
2
[1 2 3]

$ perl6 -e 'my @​a = 1,2,3; repeat { say (state @​b = @​a).pop } until $++; say @​a;'
3
2
[1 2 3]

# Weird
$ perl6 -e 'my @​a = 1,2,3; say (repeat { (state @​b = @​a).pop } until $++); say @​a;'
(3 3)
[1 2 3]

$ perl6 -e 'my @​a = 1,2,3; repeat { say (state @​b = @​a).pop } until $++; say @​a;'
3
2
[1 2 3]
$ perl6 -e 'my @​a = 1,2,3; repeat { my $a = (state @​b = @​a).pop; say $a } until $++; say @​a;'
3
2
[1 2 3]

# Yes, indeed, weird
$ perl6 -e 'my @​a = 1,2,3; say (repeat { my $a = (state @​b = @​a).pop; say $a } until $++); say @​a;'
3
3
(True True)
[1 2 3]

@p6rt
Copy link
Author

p6rt commented Feb 11, 2016

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

@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