for example append will join two lists into one, but without any check on the elements of the lists, what if I want to join two lists without duplicate elements ? (this operation is called Union in set theory)
(more info on what I'm talking about is here http://en.wikipedia.org/wiki/Set_theory#Basic_concepts)
So me and Betel made a couple of functions:
the first one is Union
(intUnionList '(a b c) '(c d e)) Returns '(a b c d e)
the second one is Intersection, it will return a list with only the items in common between the 2 argument lists.
(intIntersectList '(a b c d) '(c d e f)) Returns '(c d)
Here the 2 functions:
Code: Select all
(setq intUnionList (lambda (list1 list2)
(block (FinalList)
(setq FinalList Nil)
(enum list1 theElement1
(block (elementIndex)
(setq elementIndex (find FinalList theElement1))
(if (not elementIndex)
(setq FinalList (lnkAppend FinalList theElement1))
)
)
)
(enum list2 theElement1
(block (elementIndex)
(setq elementIndex (find FinalList theElement1))
(if (not elementIndex)
(setq FinalList (lnkAppend FinalList theElement1))
)
)
)
FinalList
)))
;--------------------------------------------------------------------------------
(setq intIntersectList (lambda (list1 list2)
(block (FinalList)
(setq FinalList Nil)
(enum list1 theElement1
(block (elementIndex)
(setq elementIndex (find list2 theElement1))
(if (not (eq elementIndex Nil))
(setq FinalList (lnkAppend FinalList theElement1))
)
)
)
FinalList
)))
What do you think ?