23 lines
739 B
Common Lisp
23 lines
739 B
Common Lisp
;;; SEQUENCES 2: REMOVE, REMOVE-IF, SUBSTITUTE (solution)
|
|
|
|
(defun drop-them (x xs)
|
|
(remove x xs))
|
|
|
|
(defun drop-negatives (xs)
|
|
(remove-if #'minusp xs))
|
|
|
|
(defun swap-them (new old xs)
|
|
(substitute new old xs))
|
|
|
|
;;; ------------------------------------------------------------------
|
|
;;; Checks. Read them - they tell you what to aim for - but leave
|
|
;;; them unchanged.
|
|
;;; ------------------------------------------------------------------
|
|
|
|
(check-equal '(a c) (drop-them 'b '(a b c b)))
|
|
(check-equal '(1 3) (drop-them 2 '(2 1 2 3 2)))
|
|
(check-equal '(1 0 2) (drop-negatives '(-1 1 0 -2 2)))
|
|
(check-equal '(3) (drop-negatives '(-5 -3 3)))
|
|
(check-equal '(x 2 x) (swap-them 'x 1 '(1 2 1)))
|
|
(check-equal '(a b a) (swap-them 'a 'z '(z b z)))
|