Files

20 lines
636 B
Common Lisp

;;; STRINGS 6: FORMAT PICKS AND CASE (solution)
(defun tick-tock (n)
(format nil "~[tick~;tock~]" (mod n 2)))
(defun quiet-title (s)
(format nil "~(~a~)" s))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal "tick" (tick-tock 0))
(check-equal "tock" (tick-tock 1))
(check-equal "tick" (tick-tock 2))
(check-equal "tock" (tick-tock 5))
(check-equal "grace" (quiet-title "GRACE"))
(check-equal "ada lovelace" (quiet-title "ADA LOVELACE"))