Patrick R. Michaud wrote:
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?

Couldn't the distinction be made in the type analysis phase?
Something similar how it would be resolved at runtime if
&postcircumfix:<[ ]>:(Int) and &postcircumfix:<[ ]>:(List of Int)
returned different types. E.g. ArrayItem and ArraySlice. Then
the assignment operator could distinguish the cases. With enough
type information the compiler could do the same analysis. Without
it the issue is left up to the runtime dispatcher. Both dispatch
targets treat the rhs different, of course. The ArrayItem case
builds an arrayref, the ArraySlice assigns the elements with
flattened @x.

Regards, TSa.

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to