Files

23 lines
658 B
Common Lisp

;;; NUMBERS 4: TYPE DECLARATIONS (solution)
(defun counted-double (n)
(check-type n integer)
(* 2 n))
(defun shrink (n)
(check-type n (integer 0 100))
(- 100 n))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal 10 (counted-double 5))
(check-equal 0 (counted-double 0))
(check-error (counted-double "five") 'type-error)
(check-equal 60 (shrink 40))
(check-equal 100 (shrink 0))
(check-error (shrink 200) 'type-error)
(check-error (shrink -3) 'type-error)