in reply to Re^2: 99 Problems in Perl6 (Lisp, Prolog, Haskell)
in thread 99 Problems in Perl6

Sweet!

Why do you flatten the array? I played with that in Pugs and the asterisk seems superfluous. It seems like one is copy the elements and the other is copying the array. I thought that maybe your version would avoid aliasing problems, but even in checking that, I'm not seeing it happening.

sub group (@array is copy) { # didn't flatten gather { while @array { take [ gather { my $h = shift @array; take $h; while @array and $h eq @array[0] { take shift @array; } } ]; } } }

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^4: 99 Problems in Perl6 (Lisp, Prolog, Haskell)
by TimToady (Parson) on Dec 15, 2006 at 23:39 UTC
    I just chose to write it as a list operator so that you could say
    @result = group 1,2,2,2,3,3,4,4,4,4,5,5,6,6;
    instead of doing it all with "scalar" arrays:
    @result := group [1,2,2,2,3,3,4,4,4,4,5,5,6,6];
    But either approach is fine.