Markus Laire wrote:

Rod Adams wrote:

TSa (Thomas Sandla▀) wrote:


You mean @a = [[1,2,3]]? Which is quite what you need for multi
dimensional arrays anyway @m = [[1,2],[3,4]] and here you use
of course @m[0][1] to pull out the 2. I'm not sure if this automatically
makes the array multi-dimensional to the type system though. That is
if @m[0,1] returns 2 as well or if it returns the list (1,2) or whatever.
Is @m[0..3] valid and what does it return? And what's the type of that
return value(s)? I can imagine many things ranging from a two element
array of refs to two element arrays up to a flattened list of 4 values.


@m[0,1] is an array slice of two elements, in this case two arrayrefs [1,2], and [3,4].
@m[0;1] is a multidim deref, referencing the 4.

@m[0..3] is valid, returning arrayref x 2, undef x 2.


I think you got these wrong. With @m = ([1,2],[3,4]) these would be true, but with @m = [[1,2],[3,4]] we have an additional reference there.


From S02: "Array and hash variable names in scalar context automatically produce references."

Since [...] produces a scalar arrayref, we end up with an arrayref one both sides of the =.

Now, I see two ways it could shake down from here:

1) the lhs ref acquires the value of the rhs ref.
2) both sides perform one level of dereferencing, and the list of elements from the rhs is copied over to the lhs. Having one one side dereference and not the other makes no sense at all.

Either way, I see the following as all being semantically equivalent:

   @m = ([1,2],[3,4]);
   @m = [[1,2],[3,4]];
   @m = (1,2; 3,4);
   @m = [1,2; 3,4];
   @m = list([1,2],[3,4]);
   @m = (); @m[0]=[1,2]; @m[1]=[3,4];
   @m[] = ([1,2],[3,4]);
   @m <== [1,2], [3,4];
   @m <== (1,2; 3,4);


If I understand Juerd correctly, the logical extension would be to have
   @m = 5;
be the same as:
   @m = list(5);

Thus saying that a lhs @ forces list context on the rhs, where I think having the rhs dictate context on the rhs makes a lot more sense.

Basically, I'm disagreeing with some of what Juerd has said.

-- Rod Adams




Reply via email to