---------- Forwarded message ----------
From: Carl Mäsak <cma...@gmail.com>
Date: Sun, Apr 5, 2009 at 9:30 AM
Subject: Re: Multi-Dimensional arrays
To: Peter Schwenn <pe...@schwenn.com>


Peter (>):
> I've had inconsistent/incorrect results, once having created an array
> of array of arrays, both while addressing elements in it as
> @A[l][m][n]=x and as @a[l][...@y ; .... as severe, for example, as
> modifying @A[16]'s contents in addressing @A[14] .

Aye; that may or may not be a bug. I've previously fallen into this trap:

$ perl6 -e 'my @a = [[0 xx 3] xx 3] xx 3; @a[1][2][0] = 7; say @a.perl'
[[[7, 0, 0], [7, 0, 0], [7, 0, 0]], [[7, 0, 0], [7, 0, 0], [7, 0, 0]],
[[7, 0, 0], [7, 0, 0], [7, 0, 0]]]

But that (if I understand correctly) is how C<xx> is specced to
behave. It doesn't create clones of the Array, it gives you several
references to the same one.

What does work, and what I settled on in Druid (which pretty much
depends on multidimensional arrays working properly), is using map:

$ perl6 -e 'my @a = map {[map {[map { 0 }, ^3]}, ^3]},  ^3;
@a[1][2][0] = 7; say @a.perl'
[[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [7, 0, 0]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]]

> Perhaps I should wait.  Or perhaps what you're saying includes a
> prohibition against using any references to @A which have two or more
> "[..]"  .  The reason I thought I could use [][] and [][][] is because
> I had no problem using @B[]{} where I had an array of hashes.

I'm not 100% sure, but I would bet that your problems stem from a
distinction such as the one above.

> Another thing I could do is to learn how to search RT to see better
> what works and what doesn't.

Yes, please do that! Not for this particular reason, but simply
because we need more people with knowledge about the tickets in RT.
Lately, they have grown unnecessarily, simply because we have too few
eyes finding closeables and duplicates.

// Carl

Reply via email to