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

Reply via email to