At 08:52 AM 8/31/00 -0400, Karl Glazebrook wrote:
>Jeremy Howard wrote:
> >
> > > we are after SIMPLE syntax. This means like C, Fortran, IDL and Matlab.
> > > Perl is about working like most people expect.
> > >
> > Yes, we are after simple syntax. We also want to make to hard things
> > possible. Therefore we want a syntax that is also flexible.
> >
> > > To access a single element we want
> > >
> > > $a[$i,$j,$k]
> > >
>
>As I said we can use other characters, I am warming to the ; proposal.
>
>I am happy with @ for slices and $ for single elements assuming the deref
>stuff can be resolved.
>
>I am anxious to avoid too many levels of brackets as they just look plain
>ugly.
>
>$a[$i;$j;$k] for a single element would do it for me, and @[10..20;10..20]
>for a slice.

Under the proposal I think Jeremy and I are both warming to, 
@a[10..20;10..20] would return a 11x11 matrix.  Is that the type of slice 
you wanted?

Here is a quick summary of the proposal:

In the raw, arrays can be indexed by two things:  ints and refs to lists of 
ints.  If it's an int it's treated as a standard 1-D array.  If it's a ref, 
it's treated as a N-dim matrix, with N being the lengths of the reffed 
array.  So the following will work:

@points = ([0,0,0],[0,0,1],[0,1,1],[0,1,0],[1,1,0],[1,1,1],[1,0,1],[1,0,0]);

for (my $i=0;i<@points;i++) {
   $matrix[$points[$i]] = $i;
}
print @matrix[@points];  # prints 12345678

Arrays could also be of the form:  @a[list1;list2], where the resulting 
array is formed by taking the cartesian product of list1 and list2 as 
indices into @a, allowing for a different style of slicing than is (easily) 
possible with the list-ref notation.  As a special optimisation, if all the 
;-separated lists are singleton lists, then you get a scaler result.  That 
means that all of the following are equivilant:

sub diagonal ($) {
   my $x = shift;
   return [$x,$x,$x];
}
$y = 0;
$rorigin = [0,0,0];
@lorigin = (0,0,0);

print $a[[0,0,0]];    # literal ref list
print $a[0;0;0];      # literal singleton ; list
print $a[[$y,$y,$y]]; # variable-based ref list
print $a[$y;$y;$y];   # variable-based singleton ; list
print $a[[@lorigin]]; # ref to copy of array variable
print $a[\@lorigin];  # ref of array variable
print $a[$rorigin];   # ref variable
print $a[diagonal(0)];# function that returns array ref

There...  8 ways to do it...

I notice that Dan Sugalski is in my CC list...  Perhaps he could chime in 
on how difficult he feels it would be to support this?

>I don't believe we should bend over backwards not to break any existing perl5
>syntax, that was done for perl4->perl5 and had led to all kinds of uglyness.

I don't think we should gratuitously break existing perl5 syntax either.


>Karl

Reply via email to