> > @a[[$i,$j,$k], [$x,$y,$z]]
> 
> I think it is more readable if you have different type of parantheses:
> @a[($i,$j,$k), ($x,$y,$z)]

The trouble is that that already has a meaning (although perhaps not a 
particularly useful one).

The list ($i,$j,$k) in scalar context evaluates to its final element, 
$k, so @a[($i,$j,$k),($x,$y,$z)] becomes equivilant to @a[$k,$z], which 
is a two-element slice of the array @a....  Not -quite- what we wanted.

What ever syntax we use is going to have to be compatable with the 
syntax used by the rest of the language.  It does no good to choose to 
use a syntax for matrix operations that already has a well-defined (if 
pointless) interpretation.  The two proposals for matrix indexing (mine 
and Jeremy Howard's) extend Perl's syntax in different, but 
perl-friendly ways.

Jeremy's @a[[$i,$j,$k],[$x,$y,$z]] syntax  would, in Perl 5 terms, be a 
semantic error.  [$i,$j,$k] is easily parsed into an anonymous array 
ref, so we are trying to index @a by (two) array refs, which doesn't 
have a meaning in Perl 5.  Using that to mean multi-dimensional array 
access is a reasonable extension.  It also means you can do things like 
@a[$point[0],$point[1]] where @point is a list of lists.
  
> Also:
> [[$i,$j,$k], [$x,$y,$z]]
> kind of resembles to creating a piddle where all these variables are the
> values, whereas in your example of accessing two elements
> @a[[$i,$j,$k], [$x,$y,$z]]
> the variables are actually indices, not the values. Two similar syntaxes,
> two different meanings open to possible mistakes and confusion.

The syntax [[$i,$j,$k],[$x,$y,$z]] already has in perl the meaning of 
"an anonymous array containing two anonymous arrays of three elements 
each".

I've not noticed any proposals for multi-dimensional array literals 
yet.  I don't have any good idea how to do it.

Besides, the "confusing" syntax you describe is analogous to:
 
   [$i,$j,$k]  creating an anon array ref, where the variables are 
values
and
   @a[$i,$j,$k] being an array slice, where the variables are indices.

the two syntaxes are as similar to what you described, with as 
different meanings, and yet perl has been living and dealing with both 
those forms for 4-5 years now without too much confusion.

> 
> More on syntax for creating pdls:
> Can we just get rid of unnecessary commas. Spaces should be good enough:
> $p = pdl [[1 2 3][4 5 6]];
> 
> Also aren't there too  many and confusing "[" and"]"s in the syntax. This
> makes difficult and unreadable to create matrices by hand? For an 3x8
> matrix (without commas):
> $p = pdl [[1 2 3][4 5 6][4 5 6][6 3 3][2 3 5][3 5 5][3 5 5][2 2 2]];
> Do you really feel that this looks like a 2-d matrix. It feels like a 3-d
> matrix to me when I first see it. This is very ugly syntax and doesn't fit
> human perception. Even though we can't visualize 10-d spaces, we are pretty
> good at visualizing 2-d objects. So this kind of complicated syntax can be
> suitable for n-d representation but the first two dimensions should be more
> natural.
> Easier syntax would be:
> $p = pdl [1 2 3, 4 5 6, 4 5 6, 6 3 3, 2 3 5, 3 5 5, 3 5 5, 2 2 2];
> or
> $p = pdl [1 2 3; 4 5 6; 4 5 6; 6 3 3; 2 3 5; 3 5 5; 3 5 5; 2 2 2];

I don't see either of these as better for human perception than

@p = [[1,2,3],
      [4,5,6],
      [4,5,6],
      [6,3,3],
      [2,3,5],
      [3,5,5],
      [3,5,5],
      [2,2,2]];

The difference is that I chose to write the 2-D structure in a 
human-visible 2-d form.  I could have written it without commas the 
same way.  It also makes it easy to go to n-d forms without a problem:

@cube = [ [[1 2]
           [2 3]],
          [[3 4]
           [4 5]],
          [[5 6]
           [6 7]]  ];

> 
> Now if you are wondering how this would scale to multiple dimensions since
> this is specific to 2-d, here is a 3x8x2 matrix:
> $p = pdl [1 2 3; 4 5 6; 4 5 6; 6 3 3; 2 3 5; 3 5 5; 3 5 5; 2 2 2][1 2 3; 4
> 5 6; 4 5 6; 6 3 3; 2 3 5; 3 5 5; 3 5 5; 2 2 2];
> or better written:
> $p = pdl [1 2 3; 4 5 6; 4 5 6; 6 3 3; 2 3 5; 3 5 5; 3 5 5; 2 2 2]
           [1 2 3; 4 5 6; 4 5 6; 6 3 3; 2 3 5; 3 5 5; 3 5 5; 2 2 2];
> 
> Is this a limited or confusing syntax? No. Here instead of assuming that
> vectors are the smallest building blocks, I assumed 2-d matrices are the
> building blocks and vectors are just 2-d matrices with the second dimention
> equal to zero. Well here is how current synta will handle a column vector
> anyway:
> $p = pdl [[3], [4], [2], [3], [4], [2], [3], [4], [2]];
> and my suggested syntax:
> $p = pdl [3 ; 4 ; 2 ; 3 ; 4 ; 2 ; 3 ; 4; 2];
> 
> As I mentioned we can visualize 2-d easily so there is nothing wrong to use
> a special syntax for the first two dimensions. Isn't this very perlish?

I see things differently...  I can easily visualize 3-d, and although I 
can't do higher, I see no reason to treat -any- particular D 
representation special.  I just don't know implement that ideal -- 
computers are linear, after all.

Two comments on your syntax:

scalers are singular, and are represented by $
arrays  are plural,   and are represented by @

Get these confused, and more experienced heads than I will complain 
about it.

The fact that PDL uses $p to represent an "array" is an artifact caused 
by Perl 5's lack of true multidimensional arrays of sufficient 
efficiency to write PDL with standard data types.  When a non-PDL-using 
Perl old-hand sees $pdl, they might think "a scalar", or "an instance 
of class PDL", or even "a reference to a hash blessed as class PDL", 
but they won't think "array".

There is no reason in Perl 6 to be forced to make that compromise -- 
yet.

> Also as I mentioned before %90 or maybe more of the time pdl will be used
> for 1-d or 2-d calculations.
> 
> Baris.
> 

-- 
     Buddha Buck                             [EMAIL PROTECTED]
"Just as the strength of the Internet is chaos, so the strength of our
liberty depends upon the chaos and cacophony of the unfettered speech
the First Amendment protects."  -- A.L.A. v. U.S. Dept. of Justice


Reply via email to