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]

Reply via email to