Effective February 22, 2024, Google Groups will no longer support new Usenet content. Posting and subscribing will be disallowed, and new content from Usenet peers will not appear. Viewing and searching of historical data will still be supported as it is done today.
Dismiss

More about arrayref/hashref in spectest suite

0 views
Skip to first unread message

Patrick R. Michaud

unread,
Nov 8, 2008, 7:39:54 AM11/8/08
to perl6-l...@perl.org
I'm still working on issues with arrayrefs and hashrefs in
the spectest suite. S02-literals/autoref.t:59 has the
following:

# Implicit referentiation of arrays in assignment to an array element
{
my @array = <a b c>;
my @other;
@other[1] = @array;

is ~@other, " a b c", '@other[$idx] = @array works (1)';
is +@other, 2, '@other[$idx] = @array works (2)';
is +@other[1], 3, '@other[$idx] = @array works (3)';
}

The idea given by the test appears to be that the
C< @other[1] = @array; > statement causes @other[1] to
contain a reference to @array. After the statement, @other
contains two elements, the second of which is an array of three
elements.

However, S03 and STD.pm seem to indicate that having @other[1]
on the left would result in a list assignment, not an item
assignment. As a list assignment, @other[1] would then get
the first element from @array, and we'd get a warning about
the leftover elements.

By way of illustration, contrast the two assignments at
the end of the following code:

my @x = <a b>;
my @y;

@y[1] = @x, 'c';
@y[1,2,3] = @x, 'c';

The second assignment would seem to clearly be a list
assignment, leaving @y with (undef, 'a', 'b', 'c').

But is the first assignment parsed as an item assignment or
a list assignment? If it is parsed as an item assignment,
how does the parser recognize it as such? If it's parsed
as a list assignment, then should we be creating an
Array reference here or merely assigning elements to
the container on the left?

Or am I missing something else altogether?

Thanks in advance for any answers,

Pm

Reply all
Reply to author
Forward
0 new messages