```On Sun, Dec 03, 2000 at 03:31:51PM +0900, Hal E. Fulton wrote:
> ----- Original Message -----
> From: Ross Mohn <rpmohn / panix.com>
> To: ruby-talk ML <ruby-talk / netlab.co.jp>
> Sent: Saturday, December 02, 2000 7:40 PM
> Subject: [ruby-talk:6757] Re: Array Intersect (&) question
>
>
> > hal9000 / hypermetrics.com (Hal E. Fulton) wrote in
> > <001901c05cc1\$ee8c75c0\$01f9fea9 / austin.rr.com>:
> >
> > >> 3) Finally, I believe there is a logic bug in the current intersect
> > >> functionality. I actually would expect that two arrays, both with the
> > >> same dup elements would yield that dup in the intersection:
> > >>
> > >>   a2 = %w# 1 1 y #      -> ["1", "1", "y"]
> > >>   a3 = %w# 1 y 1 z #    -> ["1", "y", "1", "z"]
> > >>   a2 & a3               -> ["1", "y"]
> > >>
> > >> Whereas I believe the true intersection of a2 & a3 should be
> > >> ["1", "1", "y"] . Opinions?
> > >>
> > >
> > >Hmm, I can't agree with you on this one. The very term "intersect"
> > >suggests to me a mathematical set; a set intersection (in math)
> > >never results in duplicates because sets can't have duplicates.
> >
> > Is it valid (in math) to be intersecting sets that contain duplicates? We
> > may be talking in circles here. To me, if you are intersecting things that
> > contain duplicates (and therefore already violate the mathematical set
> > rules) then you should preserve that during the intersection. -RPM
> > --
>
> Well, if I were going to apply "intersection," which is a set operator,
> I would first apply "uniq" so that I would have a set.  :) But that is
> just me.
>
> I can see that some might want the functionality you describe, though it
> seems odd and counter-intuitive to me.
>
Hi

I agree with Ross.  Presumably, if you are intersecting "pseudo-sets"
with duplicates, you WANT the duplicates.  Ruby should not second
guess you.  If you don't want the duplicates, you can easily remove
them, but its trickier to go the other way.

(How do other languages do it? Common Lisp preserves the duplicates,
in the way Ross wants:

(intersection '(1 1 y) '(1 y 1 z))

=> (1 1 y))

Regards

Peter

```