develooper Front page | perl.perl6.language | Postings from November 2008

More about arrayref/hashref in spectest suite

Thread Next
From:
Patrick R. Michaud
Date:
November 7, 2008 22:40
Subject:
More about arrayref/hashref in spectest suite
Message ID:
20081108063954.GA31658@pmichaud.com
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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About