difference

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

difference

Post by newdep »

Hi Lutz,

Im running into a problem, I thought that 'Difference returned only the
list of differences, but it also seems that it returns a Unique list. And that
is quiet annoying ;-) We have already 'Unique ' Intersect 'Filter and 'Difference
but none of those does return a difference!

Oke i could use map..but i like the simplicity of difference...

Anything that could make difference realy differ?

Norman.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

'difference' is true to the mathematical defintion of set difference as A \ B. The following link explains the difference between A - B (your suggestion) and A \ B (how its implemented):

http://planetmath.org/encyclopedia/SetDifference.html

Lutz

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The next version (development 8.6.1, due coming weekend) will contain an optional flag in 'difference' and 'intersect' to put these in list mode versus set mode and not eliminate duplicates:

Code: Select all

; normal set mode
(difference '(2 5 6 0 3 5 0 2) '(1 2 3 3 2 1)) => (5 6 0)

; optional list mode
(difference '(2 5 6 0 3 5 0 2) '(1 2 3 3 2 1) true) => (5 6 0 5 0)

; normal set mode
(intersect '(3 0 1 3 2 3 4 2 1) '(1 4 2 5)) => (2 4 1)

; optional list mode
(intersect '(3 0 1 3 2 3 4 2 1) '(1 4 2 5) true) => (1 2 4 2 1)
This makes it easy to filter lists from a list of allowed or not-allowed elements. Note that even in list mode the second list is always taken unique as a set.

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Thanks ! great addon ;-)
-- (define? (Cornflakes))

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Nice! I encountered the same problem last week.

Thanks

Peter

Locked