Let's say two people want to add a 'shuffle' method to all arrays.  Alice wants 
to have it look like this:

  method shuffle (*...@array is rw) {
      @array .= pick(*);
 }

Bob wants it to look like this:

  method shuffle (*...@array is rw) {
      @array = @array[0 .. @array/2] Z @arr...@array/2+1 .. @array];
  }

 
Thus, each wants to do the following, being able to modify the array in place:

  my @array = ^10;
  @array.shuffle;

Is it possible to modify the core Perl6Array class like that (without extra 
keywords)?  If so, is it possible for each programmer to make such a change so 
that it's lexically scoped? 

Oh, and the difference between those, for lurkers:

  perl6 $ perl6 -e 'my @a = <a b c d e f g>; [...@a[0..@a/2] 
z...@a[@a/2+...@a]].perl.say'
  ["a", "e", "b", "f", "c", "g"]
  perl6 $ perl6 -e 'my @a = <a b c d e f g>; @a .= pick(*); @a.perl.say'
  ["g", "a", "f", "c", "e", "d", "b"]

Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

Reply via email to