Re: Array/list transformations.
On 12/27/05, Larry Wall [EMAIL PROTECTED] wrote: On Tue, Dec 27, 2005 at 12:10:45AM -0500, Rob Kinyon wrote: : 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? Hmm. Assignment is already adequate for copying semantics. And binding the individual elements can presumably be done by: my [EMAIL PROTECTED] := @a[0,2,4]; What's the difference between: my @s := @a[0,2,4]; and my [EMAIL PROTECTED] := @a[0,2,4]; ? Rob
Re: Array/list transformations.
On Tue, Dec 27, 2005 at 01:13:10PM -0500, Rob Kinyon wrote: : On 12/27/05, Larry Wall [EMAIL PROTECTED] wrote: : On Tue, Dec 27, 2005 at 12:10:45AM -0500, Rob Kinyon wrote: : : 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? : : Hmm. Assignment is already adequate for copying semantics. And binding : the individual elements can presumably be done by: : : my [EMAIL PROTECTED] := @a[0,2,4]; : : What's the difference between: : : my @s := @a[0,2,4]; : : and : : my [EMAIL PROTECTED] := @a[0,2,4]; : : ? As with function parameter binding, the first would attempt to bind only the first argument, that is, @a[0]. The main difference between := and parameter binding is that := defaults to rw instead of readonly. Larry
Re: Array/list transformations.
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
Re: Array/list transformations.
On Tue, Dec 27, 2005 at 12:10:45AM -0500, Rob Kinyon wrote: : 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? Hmm. Assignment is already adequate for copying semantics. And binding the individual elements can presumably be done by: my [EMAIL PROTECTED] := @a[0,2,4]; Larry
Re: Array/list transformations.
On Thu, Dec 22, 2005 at 04:47:21PM +0100, Michele Dondi wrote: This is not a substantial issue regarding Perl 6, but is more a minor feature curiosity/meditation. It was inspired some time ago by this PM node: http://perlmonks.org/?node_id=509310 I was wondering if in addition to push(), pop() etc. there could be be rot() and roll() methods that would act upon lists (not modifying them) like thus: (qw/aa bb cc dd ee/).rot(2) # qw/cc dd ee aa bb/ (qw/aa bb cc dd ee/).rot()# qw/bb cc dd ee aa/ = same as .rot(1) (qw/aa bb cc dd ee/).roll(2) # qw/dd ee aa bb cc/ = same as .rot(-2) (qw/aa bb cc dd ee/).roll() # qw/ee aa bb cc dd/ = same as .roll(1) rot doesn't conjur the right stuff for me, sorry. Since we already have shifting operators, why not just (re)use them? If + is numeric left shift, maybe @ is array left shift. Of course, then you'd have to figure how to vary the wrapping semantics. my @a = qw/aa bb cc dd ee/; @a = @a @ 2; # or @a @= 2; my @b = @a @ 4; Okay, I'm already not liking that syntax, but the idea is the same: we have shifting ops, let capitalize on that meme. ... etc. 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. -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]