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

Arrays should flatten in for loop expressions in the absence of explicit don't-flatten clues, but they don't in Rakudo #2082

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

Comments

@p6rt
Copy link

p6rt commented Aug 20, 2010

Migrated from rt.perl.org#77340 (status was 'rejected')

Searchable as RT77340$

@p6rt
Copy link
Author

p6rt commented Aug 20, 2010

From @masak

<masak> rakudo​: for [] -> $a { say $a.perl }
<p6eval> rakudo 7b0031​: OUTPUT«[]␤»
<masak> is this correct?
<masak> put differently, do things flatten in the <EXPR> position in
the for statement?
<TimToady> [] never flattens in a list
<TimToady> so it's correct
<masak> what about this one?
<masak> rakudo​: my %h = foo => []; for %h<foo> -> $a { say $a.perl }
<p6eval> rakudo 7b0031​: OUTPUT«[]␤»
<masak> I find I do such hash accesses when iterating on quantified
Match objects. I'd like to know if I should write %h<foo> or
%h<foo>.list in the for statement.
<masak> not least because bitrot in my code seems to indicate that the
behaviour changed in Rakudo recently :)
<TimToady> I think that one should flatten
<masak> what's the easy rule that distinguishes them?
<TimToady> there's no [] or $ to prevent it in the return from .<>
<masak> so... where there's no explicit "don't flatten" clue, the
thing flattens?
<TimToady> nod
* masak submits rakudobug

@p6rt
Copy link
Author

p6rt commented Aug 21, 2010

From @pmichaud

On Fri, Aug 20, 2010 at 03​:42​:57PM -0700, Carl Mäsak wrote​:

<masak> rakudo​: my %h = foo => []; for %h<foo> -> $a { say $a.perl }
<p6eval> rakudo 7b0031​: OUTPUT«[]␤»
<masak> I find I do such hash accesses when iterating on quantified
Match objects. I'd like to know if I should write %h<foo> or
%h<foo>.list in the for statement.
<masak> not least because bitrot in my code seems to indicate that the
behaviour changed in Rakudo recently :)
<TimToady> I think that one should flatten

Initially I disagree. Consider​:

  my %h = abc => [1,2,3], def => 4; for %h<abc def> -> $x { say $x.perl; }

I'd expect that loop to iterate twice, not 4 times.
In general, I think that .{ } and .[ ] on arrays and hashes
tend to produce scalar containers (which don't flatten by default).

To get an array in a hash element to flatten, I'd suggest @​%h<abc> .

TimToady can override this interpretation, in which case we'll
switch Rakudo to match. But I fear making hash and array elements
flattening by default will have far-reaching ramifications to other
things we're doing.

Pm

@p6rt
Copy link
Author

p6rt commented Aug 21, 2010

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

@p6rt
Copy link
Author

p6rt commented Feb 24, 2014

From @coke

On Fri Aug 20 17​:53​:36 2010, pmichaud wrote​:

On Fri, Aug 20, 2010 at 03​:42​:57PM -0700, Carl Mäsak wrote​:

<masak> rakudo​: my %h = foo => []; for %h<foo> -> $a { say $a.perl }
<p6eval> rakudo 7b0031​: OUTPUT«[]␤»
<masak> I find I do such hash accesses when iterating on quantified
Match objects. I'd like to know if I should write %h<foo> or
%h<foo>.list in the for statement.
<masak> not least because bitrot in my code seems to indicate that
the
behaviour changed in Rakudo recently :)
<TimToady> I think that one should flatten

Initially I disagree. Consider​:

my %h = abc => [1,2,3], def => 4; for %h<abc def> -> $x { say
$x.perl; }

I'd expect that loop to iterate twice, not 4 times.
In general, I think that .{ } and .[ ] on arrays and hashes
tend to produce scalar containers (which don't flatten by default).

To get an array in a hash element to flatten, I'd suggest @​%h<abc> .

TimToady can override this interpretation, in which case we'll
switch Rakudo to match. But I fear making hash and array elements
flattening by default will have far-reaching ramifications to other
things we're doing.

Pm

Sorry about the delay.

02​:53 < [Coke]> Here's another ticket that requires a ruling, and perhaps a
  rethink in the 3.5 years since it was opened​: RT #​77340
02​:58 < TimToady> given current understanding of how things itemize, I think Pm
  has it right, and we should reject the ticket
02​:58 < TimToady> except that @​%h<abc> can't work
02​:58 < TimToady> must be either @​(%h<abc>) or %h<abc>.list or %h<abc>[]

Rejecting ticket, sorry.

--
Will "Coke" Coleda

@p6rt p6rt closed this as completed Feb 24, 2014
@p6rt
Copy link
Author

p6rt commented Feb 24, 2014

@coke - Status changed from 'open' to 'rejected'

@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