Re: [S29] uniq

2005-05-27 Thread TSa (Thomas Sandlaß)
Luke Palmer wrote: So I suppose that's my proposal. Allow, even encourage, overloading of =:=, but only for value types. I've been thinking that we ought to provide a standard role for making something a value type. Maybe it would require definition of =:=. I would like to propose something

Re: [S29] uniq

2005-05-19 Thread Sam Vilain
Mark Overmeer wrote: 'uniq' differs from 'sort' because there is no order relationship between the elements. A quick algorithm for finding the unique elements in perl5 is sub uniq(@) { my %h = map { ($_ => 1) } @elements; keys %h; } ...and an even quicker one is: use Set::Object;

Re: [S29] uniq

2005-05-19 Thread Damian Conway
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 remov

Re: [S29] uniq

2005-05-19 Thread Luke Palmer
On 5/19/05, Damian Conway <[EMAIL PROTECTED]> wrote: > Ingo Blechschmidt 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.

Re: [S29] uniq

2005-05-19 Thread Rod Adams
Damian Conway wrote: BTW, I am *sorely* tempted to suggest the following implementation instead: which would produce: uniq ; # uniq { lc } ; # 'a'|'A', 'b', 'C'|'c', 'd' uniq { abs $^value } 42, 23, -23, 23, 42;# 42, 23|-23 But I'd

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Damian Conway wrote: > BTW, I am *sorely* tempted to suggest the following implementation > instead: [...] > which would produce: > > uniq ; # > > uniq { lc } ; # 'a'|'A', 'b', > 'C'|'c', 'd' > > uniq { abs $^value } 42, 23, -23,

Re: [S29] uniq

2005-05-19 Thread Damian Conway
Ingo Blechschmidt wrote: Is it intentional that there's no uniq in the current S29[1] draft? See [2] for Damian saying that uniq is probably in. It still probably is. I wondered what uniq's default comparator should be, =:=? &infix:<~~> Should it be possible to give an own comparator block, simil

Re: [S29] uniq

2005-05-19 Thread Adriano Ferreira
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

Re: [S29] uniq

2005-05-19 Thread Juerd
Ingo Blechschmidt skribis 2005-05-19 21:07 (+0200): > 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 Which leads to lots of |so

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Adriano Ferreira wrote: > quoting Damian's original mail[1]: >> uniq - remove duplicates without reordering > ^^ > > Would not that mean the original order of the first ocurrence is > preserved? This is what Ruby Array#uniq does: > > [4,1

Re: [S29] uniq

2005-05-19 Thread Adriano Ferreira
The former implementation can be shortened: sub uniq { my %h; return grep { ! $h{$_}++ } @_; } But realize that none of the proposed solutions (which are based on hashes for computing the return) is amenable to the extension Ingo called for with comparator blocks. Adriano.

Re: [S29] uniq

2005-05-19 Thread Adriano Ferreira
quoting Damian's original mail[1]: > uniq - remove duplicates without reordering ^^ Would not that mean the original order of the first ocurrence is preserved? This is what Ruby Array#uniq does: [4,1,2,4,2,3,5].uniq => [ 4, 1, 2, 3, 5] The b

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Mark Overmeer wrote: > * Ingo Blechschmidt ([EMAIL PROTECTED]) [050519 16:52]: >> Should it be possible to give an own comparator block, similar as >> with grep? E.g. >> uniq ; # >> >> uniq:{ abs $^a == abs $^b } 42, 23, -23, 23, 42 >> # 42, 23, 42 > > 'uniq' d

Re: [S29] uniq

2005-05-19 Thread Mark Overmeer
* Ingo Blechschmidt ([EMAIL PROTECTED]) [050519 16:52]: > Should it be possible to give an own comparator block, similar as with > grep? E.g. > uniq ; # > > uniq:{ abs $^a == abs $^b } 42, 23, -23, 23, 42 > # 42, 23, 42 'uniq' differs from 'sort' because there is no

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Rod Adams wrote: >>I wondered what uniq's default comparator should be, =:=? > I'd have gone with ~~ Even better. :) --Ingo -- Linux, the choice of a GNU | Row, row, row your bits, gently down the generation on a dual AMD | stream... Athlon!|

Re: [S29] uniq

2005-05-19 Thread Rod Adams
Ingo Blechschmidt wrote: Hi, three quick questions: Since Aaron is still getting up to speed, I'll take a stab at these. Is it intentional that there's no uniq in the current S29[1] draft? See [2] for Damian saying that uniq is probably in. Just hasn't been entered. I wondered what uniq's def