From: "Hal E. Fulton" Date: 2000-12-03T15:31:51+09:00 Subject: [ruby-talk:6760] Re: Array Intersect (&) question ----- Original Message ----- From: Ross Mohn To: ruby-talk ML 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. But as for the ordering question... I am not sure I understand this at all. Given: a = [1,3,5,7] and b = [2,5,3,6], should a&b be [3,5] or [5,3] if we want to "preserve" order??? Hal Fulton