> On Fri, 4 Jul 2003, Damian Conway wrote:
> 
> > > Will it be possible (or sane even) to bind a variable to an array slice
> > It *should* be, since it's possible (if ungainly) to do it in Perl 5:
> 
> Ouch, blatant abuse of perl5's aliasing with @_ and globs ;) Can I also
> assume that you can also pass around a 'reference' to an array slice e.g
> 
>   sub array_slice(Array @ar, int $begin, int $end) {
>     ## does the binding syntax := exist in unary form?
>     ## or would this be better suited to bound at the lvalue end?
>     return [EMAIL PROTECTED] $begin .. $end ];

I fear that this might take a reference to each element in the slice,
rather than a reference to the slice....

Actually, you can't reference a slice!  Where the heck does the
reference point?  I would probably do:

      my @ret := @ar[0][ $begin .. $end ];
      return [EMAIL PROTECTED];

Which would likely use an extra level of indirection in its
implementation, but that's okay.

In any case, this is highly hypothetical, and these semantics should
be nailed down in the upcoming[1] Apocalypse.

Luke

[1] Term used lightly. :-)

>   }
> 
>   my @array = << un deux trois quatre cinq six >>;
>   my @slice = array_slice( @array, 2, 4 );
> 
>   @slice    = << san shi go >>;
>   print @array;
> 
>   __output__
> 
>   un deux san shi go six
> 
> As opposed to an explicit binding assignment, or is this perhaps a step
> too far (in which direction is left to the discretion of the reader)?
> 
> Dan Brook

Reply via email to