In a message dated 24 Sep 2002, Aaron Sherman writes:
> Grrr... I want that to work, really I do, but since, as Larry has
> pointed out, there's no functional difference between an array ref and
> an array in Perl 6, they would be the same. This is because push is
> almost certainly defined as:
>
>         sub push(@target, *@list) { ... }
>
> Regardless of this entire conversation, that problem exists in Perl 6 as
> described in the apocalypses, doesn't it? The way to avoid this is to
> say that array refs behave the same as arrays in every way *except* as
> pertains to list flattening, and in that case, explicit flattening is
> required, otherwise the ref is kept in the flattened array.
>
> Does this make sense?

Yikes.  You might be right.  According to Larry,

  $a = (1,2,3);

is equivalent to

  $a = [1,2,3];

because they're both equivalent to

  $a = scalar(1,2,3)

which converts the list to an arrayref.  This only tells us about the
behavior of lists in scalar context, though--it says nothing about the
behavior of parens in a list or list-flattening context.  Is this key to
push's behavior?  Perhaps parens do not construct a list in list context,
but leave whatever is receiving the list and caused the list context to
deal with the elements, i.e., it auto-flattens a paren'ed list if one is
present but not a square-bracketed one?

In that case, we could once again DWIM so that

  push @a, 1, 2, 3;

is equivalent to

  push @a, (1,2,3);

but not to

  push @a, [1,2,3];

I agree, though, that this is getting highly magical.  Perhaps
parens-creating-arrayrefs is something that be considered specialized and
arcane and not something that programmers should do, because square
brackets are much more consistent.  I know that's a dodge, but maybe
it's the right dodge. :-)

Trey

Reply via email to