union-help

Discussion of Common Lisp
Post Reply
murali
Posts: 15
Joined: Fri Jul 01, 2011 10:11 am

union-help

Post by murali » Fri Jul 01, 2011 10:44 am

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)

I X Code X 1
Posts: 59
Joined: Sun May 29, 2011 8:52 pm
Location: NY
Contact:

Re: union-help

Post by I X Code X 1 » Fri Jul 01, 2011 11:36 am

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)

Post Reply