develooper Front page | perl.perl6.language | Postings from May 2005

Re: [S29] uniq

Thread Previous | Thread Next
From:
Damian Conway
Date:
May 19, 2005 20:37
Subject:
Re: [S29] uniq
Message ID:
428D5B69.7030908@conway.org
Luke wrote:

>>>I wondered what uniq's default comparator should be, =:=?
>>
>>&infix:<~~>
>  
> Woah there.  ~~ is a good comparator and all, but it's not the right
> one here.  ~~ compares an object and a pattern to see if they match. 
> That makes it the right choice for when and grep.  But we're trying to
> remove elements that are *the same*, not elements that *match*.

Ah, I missed Larry's message last week where he mused:

     > :     3 =:= 3; # always true?
     > :     3.id ~~ 3.id; # ditto?
     >
     > I think immutable values could work that way, especially if we
     > want to store only a single representation of each immutable
     > string.

If that's now the behaviour of =:= on non-referential values, then I agree 
that C<uniq> should compare with the =:= operator.

Of course, that presupposes quite a bit of smarts on the part of the operator.
For example, we'd also need to decide what these evaluate to:

     3 =:= 3.0  # ????

     3 =:= '3'  # ????

They're surely not identical, but you'd probably want C<uniq> to think so.

Or maybe you just have to SWYM and write:

     @uniq_nums = uniq +«@nums;

or:

     @uniq_strs = uniq ~«@strs;

if you have heterogeneous data.

Damian



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About