about summary refs log blame commit diff stats
path: root/cdbc.lisp
blob: 57e04e565e9daab53650a2f196cb6b282a741c0c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                                                                                   

                                                                        







                                                                     
;; Ported from https://rosettacode.org/wiki/Assertions_in_design_by_contract#Eiffel
;; Arguably not *quite* design-by-contract, but very close in vanilla CL
;;
;; NB: This has non-essential complexity compared to the ISLisp version.
(defun average-of-absolutes (values)
  (declare (list values))
  (assert (> (length values) 0))
  (let ((res (/ (reduce #'+ (mapcar #'abs values)) (length values))))
    (assert (>= res 0))
    (the fixnum res)))
;; (average-of-absolutes '(1 3))
;; (average-of-absolutes '())