On 12/22/05, Jonathan Scott Duff <[EMAIL PROTECTED]> wrote:
> On Thu, Dec 22, 2005 at 04:47:21PM +0100, Michele Dondi wrote:
> > Also I wonder if one will be able to push(), pop(), etc. array slices as
> > well whole arrays. A' la
> >
> > my @a=qw/aa bb cc dd ee/;
> > my $s=pop @a[0..2];  # or [0,2] or just [0] for that matters!
> > # $s='cc';
> > # @a=qw/aa bb dd ee/; => same as what I can do with slice()
> >
> > Not terribly necessary, but indeed consistent IMHO.
>
> Not quite sure why you'd want this, but if we have something like this:
>
> my @a = qw/aa bb cc dd ee/;
> my @slice :=  @a[0..2];
> my $s = pop @slice;
>
> (where @slice is a "reference" to part of @a)
>
> You get what you want and more.

To echo Scott's point, @a[0..2] === @a.splice(0,3).

Now, a more interesting problem is @a[0,2,4], which doesn't map to a
single splice() call. Ruby's syntax for this is problematic, which
points to a problem with how the solutionspaces are mapping to the
problemspaces.

Creating an array whose positions are aliases for positions in another
array can be useful. How about

    my @s := @a[0,2,4] is alias;

    @a[2] = 3; # @s[1] == 3
    @s[1] = 4; # @a[2] == 4

The default slicing behavior would default to "is copy", to preserve
the current semantics. Does that sound reasonable?

Rob

Reply via email to