On Sun, Jun 03, 2007 at 10:23:44PM -0700, Jonathan Lang wrote:
: Let me see if I understand this correctly:
: * In list context, a list of captures gets flattened.
: * In slice context (a variant of list context), a list of captures
: doesn't get flattened.
More than that, the captures get turned into sublists (subarrays?)
that prevent any subsequent flattening.
: * In hash context (another variant of list context), a list of
: captures gets flattened, and then grouped into Pairs.
: * In item context, a list of captures becomes a single Array object,
: and the question about whether or not it gets flattened gets deferred
: until its contents get looked at in list, slice, or hash context.
That's the intent. $() used to assume @@ inside till this latest
change, but that seemed insufficiently lazy to me...
But it kinda means there's yet another list context that doesn't
decide yet, used explicitly by the insides of \(...) and implicitly
by the $() context. Not sure if it needs a name yet, or whether it's
a design smell. Arguably "list" should be non-committal and we give
@() a different name like "flat", but that grates in my brain for
some reason, if only because most list contexts would in the end
be flat anyway. And "list" in English already implies something
flatter than, say, an "outline".
: Meanwhile, 'zip' produces a list of captures - which, because list
: context is the default "plural" context, immediately gets flattened
: most of the time. As I see it, then, the serial equivalent to
: 'zip(@a;@b)' would be '(@a;@b)', and 'list(@a;@b)' would be the serial
: equivalent to 'list(zip(@a;@b))'.
That doesn't make sense to me. You seem to be thinking that semicolon
has zip semantics, when it doesn't. All ; does is make a list of
captures. list() flattens any ; by interpolating the captures when
you bind to list's *@ argument, but zip binds to *@@ so it slices
it instead so that it can deal with the lists in parallel rather
than serially. And the list() in list(zip()) would just listify the
*results* of zip, not the arguments to zip...
: Or does '(@a;@b)' default to slice context?
Parentheses don't supply context. They only group. (@a;@b) returns
a list of captures. It requires a binding (or other sigil) coercion
to supply context.