Files

33 lines
1.0 KiB
Common Lisp

;;; STRINGS 6: FORMAT PICKS AND CASE
;;;
;;; FORMAT has its own conditional, for choosing between texts:
;;;
;;; (format nil "~[tick~;tock~]" 1) => "tock"
;;;
;;; The argument is a number: 0 picks the first branch, 1 the
;;; second. And ~( ... ~) folds everything between them to lower
;;; case - STRING-DOWNCASE in FORMAT's clothing:
;;;
;;; (format nil "~(~a~)" "GRACE") => "grace"
;; TODO: "tick" on an even N, "tock" on an odd one - let FORMAT
;; choose.
(defun tick-tock (n)
(format nil "tick"))
;; TODO: The title S, downcased.
(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"))