From: David Alan Black Date: 2000-12-03T22:15:32+09:00 Subject: [ruby-talk:6764] Re: Array Intersect (&) question Hello -- On Sun, 3 Dec 2000 peter.wood@worldonline.dk wrote: > 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)) And order is significant, though (not(or(to digress into Lisp)anything)) the significance varies among Lisps. GNU Common Lisp: >(intersection '(1 1 2) '(1 2 2)) (2 1 1) >(intersection '(1 2 2) '(1 1 2)) (2 2 1) Emacs Lisp: (intersection '(1 1 2) '(1 2 2)) => (2 2 1) (intersection '(1 2 2) '(1 1 2)) => (2 1 1) Funnily enough, this discussion takes me back to my Jotto program, which was my first non-trivial... well, non-very-short... Ruby program, and where one of the playing modes requires adding up how many letters the two words have, regardless of position in the words. The question being: how many letters do "agree" and "anger" have in common, and does it matter which is the guess and which the guessee? (Not that I care much -- I always play the position-sensitive version anyway :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav