I'm getting started in Lisp, and working through the problems in Lisp: Gentle Introduction to Symbolic Computation. In Chapter 8 p. 217 is the following Exercise 4:
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:
The error message I get back from Lispworks is:
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:
(MAPUNION #'CDR '((1 a b c) (2 e c j) (3 f a b c d)))
should return the set (a b c e j f d).Here is my solution:
(defun mapunion (f l)
(cond ((null l) nil)
((null (mapcar f l) nil)
(t (reduce #'union (mapcar f l)))))
Simple right? Well it crashes under Lispworks (Personal Edition 5.1.1 PowerPC) But works fine under Clozure CL64 (Version 1.4-dev (13119 (PPC64)).The error message I get back from Lispworks is:
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
Is there something wrong with my code that would cause it to crash under Lispworks but not Clozure?