This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

union-help

2 posts · 882 views

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

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.
(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.
COMMON-LISP-USER>
(my-union '(a b c d) '(c a g))

(A B C D G)