Wave 4: add sequences/vectors/files chapters, 23 exercises, quiz3, finish ceremony, PCL table
This commit is contained in:
1 parent
77843402fa
commit
4675bd1106
76 files changed
+2505
-14
No files matched your search
@@ -0,0 +1,26 @@
|
||||
;;; STRINGS 5: NUMBERS IN FORMAT
|
||||
;;;
|
||||
;;; ~a prints any value plainly. ~d and ~f print numbers with more
|
||||
;;; care, and both take modifiers: a COLON on ~d groups the digits,
|
||||
;;; (format nil "~:d" 1234567) => "1,234,567"
|
||||
;;; and a number after a comma on ~f fixes the decimals,
|
||||
;;; (format nil "~,2f" pi) => "3.14"
|
||||
|
||||
;; TODO: N widgets, grouped for humans: "1,234,567 widgets".
|
||||
(defun price-tag (n)
|
||||
(format nil "~d widgets" n))
|
||||
|
||||
;; TODO: LABEL is about N, with exactly two decimals:
|
||||
;; "pi is about 3.14".
|
||||
(defun fixed (label n)
|
||||
(format nil "~a is about ~a" label n))
|
||||
|
||||
;;; ------------------------------------------------------------------
|
||||
;;; Checks. Read them - they tell you what to aim for - but leave
|
||||
;;; them unchanged.
|
||||
;;; ------------------------------------------------------------------
|
||||
|
||||
(check-equal "1,234,567 widgets" (price-tag 1234567))
|
||||
(check-equal "7 widgets" (price-tag 7))
|
||||
(check-equal "pi is about 3.14" (fixed "pi" pi))
|
||||
(check-equal "e is about 2.72" (fixed "e" 2.718281828))
|
||||
Reference in new issue
Block a user