[forwarded submission from a non-member address -- rjk]
From: Damian Conway <[EMAIL PROTECTED]>
Date: Sun, 8 Jul 2001 00:50:04 +1000 (EST)
Subject: RE: [Boston.pm] Re: array and hash slices in Perl 6
To: [EMAIL PROTECTED], "Tolkin, Steve" <[EMAIL PROTECTED]>
Steve wrote:
> I have a few followup questions, interspersed.
> > > Larry says the syntax for hash slices and array slices will
> > > change in Perl 6. Does anyone know at this point what the new
> > > syntax for array slices and hash slices looks like?
> >
> > Very probably like I described in Exegesis 2:
> >
> > @array[@indices]
> >
> > %hash[@keys]
>
> Here you use square brackets after the hash name, but below
> you use curly braces. Which is it?
Sorry, I was rushed. [note to self: must write DWIM::CutAndPaste]
The correct syntaxes are:
@array[@indices]
%hash{@keys}
> > > Will it be possible to automatically translate the Perl
> > 5 to Perl 6?
> >
> > 95% possible, yes. Certainly standard slices will translate.
>
> I hope these examples are in the 95%.
I would expect so.
> DO you have any examples of what it might do wrong
No. Not yet, I'm afraid. Apart from obvious things like typeglobs and
pseudohashes (which it won't be able to translate since they won't exist
in Perl 6)
> > %f{@mff_feed_cols} = split(/\|/, $line );
>
> (The line above is where you used curly brace after the hash name,
> as mentionned earlier.)
This line was correct.
> A general question: I think in principle we could remove the
> @ from @foo[something] without loss of information -- the square
> braces tell us that foo is an array. Is this true?
No necessarily. Because the derefencing dot will be usually optional
in Perl 6, something like this:
foo[something]
will probably mean:
foo().[something]
> If so has any thought been given to making the @ and %
> optional in certain contexts?
No. My own feeling would be that this would introduce far too many
special cases. The reason we have changed the way sigils work is
specifically to avoid that.
> I mentionned in my originalk poost that in Perl 5 one cannot have
> a reference to a slice. Is this still true?
It's not even true now!
There's no direct syntax for it, but it's trivial to create a reference
to a slice:
my @array = (1,2,3,4,5);
my $slice = sub{\@_}->(@array[1,3,4]);
print "@array\n";
print "@$slice\n";
$slice->[1] = 99;
print "@array\n";
print "@$slice\n";
(For certain values of "trivial, that is ;-)
Damian