intersection
From: Tuang (tuanglen_at_hotmail.com)
Date: 01/28/04
- Next message: Erik Naggum: "Re: Lisp's future"
- Previous message: Espen Vestre: "Re: Length of Lisp programs"
- Next in thread: Marco Gidde: "Re: intersection"
- Reply: Marco Gidde: "Re: intersection"
- Reply: Erik Naggum: "Re: intersection"
- Reply: Marco Antoniotti: "Re: intersection"
- Reply: Kaz Kylheku: "Re: intersection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Jan 2004 01:14:41 -0800
I'm a bit confused about how "intersection" is supposed to work in
Common Lisp.
The Hyperspec says the following about intersection:
"The intersection operation is described as follows. For all possible
ordered pairs consisting of one element from list-1 and one element
from list-2, :test or :test-not are used to determine whether they
satisfy the test [of equality]....For every pair that satifies the
test, exactly one of the two elements of the pair will be put in the
result."
That tells me that if you have 3 A's in one list and 2 A's in the
other, you'll have six possible ordered pairs containing one A from
each list. Taking one from each pair, it sounds as though there should
be six A's in the result. Of course you could remove a pair, after
adding one A to the result, as soon as you get a match, but then you
wouldn't be considering "all possible ordered pairs".
Trying it out with CLISP (on Win32) to help myself understand it, I
get the following:
> (intersection '(A A A D E) '(A A B C))
(A A A)
> (intersection '(A A B C) '(A A A D E))
(A A)
Well, now I'm even more confused. At the very least, it would seem to
me that (intersection X Y) ought to be the same as (intersection Y X),
though potentially in a different order.
I think that the second is what I would normally consider
intersection, which is sharing an element in common in a venn diagram.
If set X contains 2 A's and set Y contains 3 A's, then drawing the
intersecting circles, you could put two A's in the shared (overlapped)
part with one more A in Y but outside the shared part. The
intersection would be those items in the shared region, meaning 2 A's
in the intersection.
I don't know. Is this just a bug in CLISP, or a misstatement in the
Hyperspec, or some misunderstanding on my part? I've been assuming
that something fundamental like intersection would be implemented
everywhere with the same 5-6 lines of code that have been used since
the dawn of Lisp.
Thoughts?
- Next message: Erik Naggum: "Re: Lisp's future"
- Previous message: Espen Vestre: "Re: Length of Lisp programs"
- Next in thread: Marco Gidde: "Re: intersection"
- Reply: Marco Gidde: "Re: intersection"
- Reply: Erik Naggum: "Re: intersection"
- Reply: Marco Antoniotti: "Re: intersection"
- Reply: Kaz Kylheku: "Re: intersection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|