Files
lisplings/solutions/02_functions/functions5.lisp
T

18 lines
656 B
Common Lisp

;;; FUNCTIONS 5: PRODUCING VALUES (solution)
(defun split-money (cents)
(values (floor cents 100) (mod cents 100)))
(defun half-and-double (n)
(values (/ n 2) (* n 2)))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal '(2 65) (multiple-value-list (split-money 265)))
(check-equal '(0 5) (multiple-value-list (split-money 5)))
(check-equal '(3 12) (multiple-value-list (half-and-double 6)))
(check-equal '(7/2 14) (multiple-value-list (half-and-double 7)))