Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Aliasing an array slice
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Luke Palmer  
View profile  
 More options Jul 5 2003, 3:48 pm
Newsgroups: perl.perl6.language
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Date: 05 Jul 2003 13:00:10 -0600
Local: Sat, Jul 5 2003 3:00 pm
Subject: Re: Aliasing an array slice

> > On Sat, Jul 05, 2003 at 09:51:29AM -0600, Luke Palmer wrote:

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

> > Of course not. I presume it points to something non-existent just like
> > a substring reference would in perl5 :-)

> > $ perl -le '$a = "pie contest"; $b = \substr $a, 1, 9; $$b = "arro"; print $a'
> > parrot

> I don't think you're supposed to do that:

>     % perl -le '$a = "foobar';  $b = \substr $a,2,3; $a .= "jibby"; $$b = "OBA"; print $a'
>     foobarjibby

> Because it copies the buffer to resize, and $b points back into the old buffer...

Forget I said that.  I put $b = "OBA" in my command line instead of
$$b.  It works.

Luke

> But a slice can be used as an lvalue, so I guess it would be valid to
> reference it (just like substr *should* be).

> The tricky stuff comes in in cases like:

>     my @a = (1,2,3,4,5);
>     my $sref = \@a[1..3];
>     shift @a;
>     @$sref = (4,3,2);
>     @a  # ?  (4,3,2,5) or (2,4,3,2) ?

> Those are just semantics to be nailed down, but it's tricky
> nonetheless... oh and let's not forget multidimensional slices.

> This really comes down to an issue that I've been biting my
> fingernails about for some time: iterators.  There are two mutually
> exclusive kinds of iterator semantics:  list and array.  In the above
> example, (4,3,2,5) would be list semantics; (2,4,3,2) would be array.
> And both of them are correct (or wrong) in certain applications.

> For implementation reasons, I'm not sure it's possible to have both
> kinds of iterator pointing into the same kind of array.  Perhaps we
> need a List class for an array which doesn't support indexing... but
> then it doesn't really deserve the @ medal does it?

> Hmm...

> Luke

> > Nicholas Clark


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.