23 lines
719 B
Common Lisp
23 lines
719 B
Common Lisp
;;; STRINGS 7: NEWLINES AND COLUMNS (solution)
|
|
|
|
(defun add-line (s)
|
|
(format nil "~&~a" s))
|
|
|
|
(defun right-column (name width)
|
|
(format nil "~v@a" width name))
|
|
|
|
(defun receipt (item price)
|
|
(format nil "~8a~4@a" item price))
|
|
|
|
;;; ------------------------------------------------------------------
|
|
;;; Checks. Read them - they tell you what to aim for - but leave
|
|
;;; them unchanged.
|
|
;;; ------------------------------------------------------------------
|
|
|
|
(check-equal "hi" (add-line "hi"))
|
|
(check-equal "parrot" (add-line "parrot"))
|
|
(check-equal " ada" (right-column "ada" 6))
|
|
(check-equal "hi" (right-column "hi" 2))
|
|
(check-equal "tea 2" (receipt "tea" 2))
|
|
(check-equal "coffee 3" (receipt "coffee" 3))
|