newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newdep on May 22, 2005, 03:31:20 AM

Title: difference
Post by: newdep on May 22, 2005, 03:31:20 AM
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.
Title:
Post by: Lutz on May 22, 2005, 06:39:29 AM
'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
Title:
Post by: Lutz on June 28, 2005, 02:19:26 PM
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:



; 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
Title:
Post by: newdep on June 28, 2005, 03:27:28 PM
Thanks ! great addon ;-)
Title:
Post by: pjot on June 28, 2005, 03:33:41 PM
Nice! I encountered the same problem last week.



Thanks



Peter