28 lines
920 B
Common Lisp
28 lines
920 B
Common Lisp
;;; SEQUENCES 4: EVERY, SOME, SEARCH, MERGE (solution)
|
|
|
|
(defun all-fit (f xs)
|
|
(every f xs))
|
|
|
|
(defun needle-at (needle hay)
|
|
(search needle hay))
|
|
|
|
(defun weave (a b)
|
|
(merge 'list a b #'<))
|
|
|
|
;;; ------------------------------------------------------------------
|
|
;;; Checks. Read them - they tell you what to aim for - but leave
|
|
;;; them unchanged.
|
|
;;; ------------------------------------------------------------------
|
|
|
|
(check-equal t (all-fit #'plusp '(1 2 3)))
|
|
(check-equal nil (all-fit #'plusp '(-1 2 3)))
|
|
(check-equal t (all-fit #'plusp '()))
|
|
(check (some #'minusp '(1 -2 3)))
|
|
(check-equal 1 (needle-at '(b c) '(a b c d)))
|
|
(check-equal 2 (needle-at '(2 3) '(1 5 2 3)))
|
|
(check-equal 1 (needle-at "ana" "banana"))
|
|
(check-equal nil (needle-at '(9) '(1 2 3)))
|
|
(check-equal '(1 2 3 4) (weave (list 1 3) (list 2 4)))
|
|
(check-equal '(0 1 4 9) (weave (list 4) (list 0 1 9)))
|
|
(check-equal '(2 3) (weave (list 2 3) (list)))
|