Write MAPUNION, an applicative operator that takes a function and a list as input, applies the function to every element of the list, and computes the union of all the results. Example:
Code: Select all
(MAPUNION #'CDR '((1 a b c) (2 e c j) (3 f a b c d)))
Here is my solution:(a b c e j f d).
Code: Select all
(defun mapunion (f l)
(cond ((null l) nil)
((null (mapcar f l) nil)
(t (reduce #'union (mapcar f l)))))
The error message I get back from Lispworks is:
Code: Select all
CL-USER 3 > (mapunion #'cdr '((1 a b c) (2 e c j)))
Error: Illegal instruction(4) [code 20EFE1A0] at 20EFEB78
1 (abort) Return to level 0.
2 Return to top loop level 0.
Type :b for backtrace, :c <option number> to proceed, or :? for other options
CL-USER 4 : 1 > :b
Call to ERROR