cactus: The answers to the exercises look perfectly reasonable, in the context of the tutorial that you're looking at. Apart from one or two minor style issues, mostly to do with indentation, the caveat that I would mention is that you should be aware that you are being exposed to atypical Lisp code. It's understandable that the tutorial starts with recursive definitions of list processing operators, but in doing so it is less teaching you about how to write Lisp code and more teaching the the concepts that underpin list manipulation.
To take as an example your final two answers. To compute the fibonnaci numbers, you give a perfectly good answer that reflects the natural recursive definition:
(defun fib (n)
;; altering the rules slightly by defining fib(0) as 0,
;; not 1.
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2)))))
but this happens to scale really badly. Try tracing the execution of, say,
(fib 20) – or timing execution of
(fib 30) – you'll see a large number of calls, all computing intermediate values. The neat bit about Lisp is how easy it is to fix this scaling problem:
(let ((table (make-hash-table)))
(defun fib (n)
(or (gethash n table)
(setf (gethash n table)
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2))))))))
where we cache previous answers in a hash table. Alternatively, we should perhaps solve the difference equation and simply write
(defun fib (n)
(round #i"(((1 + sqrt(5)) / 2)^^n - ((1 - sqrt(5)) / 2)^^n)/sqrt(5)"))
or else, if the rounding errors start to bite in that version, rewrite as
(defun fact (n)
(if (= n 0)
1
(* n (fact (- n 1)))))
(defun fib (n)
(declare (fixnum n))
(/ (loop for k fixnum from 1 to n by 2
sum (/ (* (expt 5 (/ (1- k) 2)) (fact n)) (fact k) (fact (- n k))))
(expt 2 (1- n))))
On a different note, for your my-merge problem, it would be rather more idiomatic to write it as:
(defun my-merge (x y)
(reduce #'* (mapcar #'+ x y)))
(I personally wouldn't use
cond in any case when there are only two branches, but that is a style matter that reflects how much editor macrology you're comfortable with).
I hope that helps.
ObRelease: SBCL 0.7.10 today; with a large slew of bugfixes, particularly to CLOS. Not a bad Common Lisp environment, even if I do say so myself.