Larry Wall larry-at-wall.org |Perl 6| wrote:
On Mon, Jun 01, 2009 at 08:23:41PM -0700, yary wrote:
: How does one create an anonymous multidimensional array in p6? Not an
: array of arrays or a capture of captures...
But I would expect a shaped array to be able to coerce either of
those into its internal format. And coercing captures into
structure is basically what @@/slice context is for.
Right, after meditating on that very thing a few days ago, I conclude
@A = @list;
should work when one of the "containers" on the left happens to be
shaped. The right is flattened, losing any structure it may have had,
including the properly shaped thing already, a single linear list, or a
different shape with a suitable number of elements.
I would suggest that the assignment demand sufficient elements to fill,
or be an integral number of lower-level units if the highest dimension
is unspecified. You can always make up the difference by sticking 0 x *
at the end of the right-hand-side if that was your intent.
And it should be an error if dimensions other than the highest are
unspecified. How can it know how to shape it? Use an explicit command
to shape up the argument in that case.
Also, if you were using an array of arrays, this will clobber that and
fill the top array with items. If the top array is declared to be of
Arrays, then the assignment will fail just like any other type
constraint. But if the second-level arrays are fixed size, you can
always write |@A on the left to re-fill those from the right hand side.