On 5/19/05, Ingo Blechschmidt <[EMAIL PROTECTED]> wrote:
> I read this as that uniq should behave like Unix's uniq(1), i.e.
> removing only successive duplicates, e.g.:
>  uniq [3,3,3,4,3]   =>   [3,4,3]   # what I meant
>  uniq [3,3,3,4,3]   =>   [3,4]     # what you meant

That has been discussed a few days ago at ruby-talk mailing list.
While standard 'uniq' in Ruby works by removing duplicates, unlike
Unix utility, the action of compressing a run of elements into a
single element was named 'squeeze'.

In P5:
sub squeeze {
 my ($y, $last);
 return grep { ($y, $last) = ($_ eq $last, $_); !$y } @_;
}

In Perl 6, 'eq' would be replaced by '~~' as said before. As Juerd
have said, not sure about how useful this may be.

If 'uniq' does not respect the original order of the elements, it is
not more than (1) convert list to a set, (2) convert back to a list.
If that's the intention, maybe we're better using only hashes or any
set-like implementation. There is also the variant of eliminating
duplicates in-place or constructing a new list.

Adriano.

Reply via email to