2.17
(defun last-pair(list)2.18
(if (null (cdr list))
list
(last-pair (cdr list))))
(defun jd-reverse(list)2.20
(if (null list)
nil
(append (jd-reverse (cdr list)) (list (car list)))))
(defun same-parity(item &rest others)2.21
(let ((temp (list item)))
(dolist (other others)
(if (= (rem item 2) (rem other 2))
(setf temp (append temp (list other)))))
temp))
In Common Lisp, there are a lot of mapping function.
(defun square-list(items)2.22
(if (null items)
nil
(cons (expt (car items) 2)
(square-list (cdr items)))))
(mapcar #'square (list 1 2 3 4 5))
(defun for-each(f items)
(dolist (item items)
(funcall f item)))
No comments:
Post a Comment