Page 1 of 1

union-help

Posted: Fri Jul 01, 2011 10:44 am
by murali
Write the function UNION which computes the set theoretic
union of two lists. For example,


(union '(a b c d) '(c a g))


returns the list (a b c d g)

Re: union-help

Posted: Fri Jul 01, 2011 11:36 am
by I X Code X 1
Really should try to post some code so people aren't just giving you the answer, but here's something to get you started on solving your problems.

Code: Select all

(defun my-union (list1 list2)
  (remove-duplicates (append list1 list2) :from-end t))
This simply asks for two lists, combines them, and then removes the duplicates. As union does.

Code: Select all

COMMON-LISP-USER>
(my-union '(a b c d) '(c a g))

(A B C D G)