Discussion of Common Lisp


Postby 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)
Posts: 15
Joined: Fri Jul 01, 2011 10:11 am

Re: union-help

Postby 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
(my-union '(a b c d) '(c a g))

(A B C D G)
User avatar
I X Code X 1
Posts: 59
Joined: Sun May 29, 2011 8:52 pm
Location: NY

Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 1 guest