about summary refs log blame commit diff stats
path: root/dbc.lsp
blob: fc6e5d00d9df084249838d99d94832575f009965 (plain) (tree)
1
2
3
4
5
6
7
8
9




                                                                                   
                              

                                                                                      
              
                               



                                                                      
;; Ported from https://rosettacode.org/wiki/Assertions_in_design_by_contract#Eiffel
(require "contract")
;; (set-dynamic *use-contract* nil)
(defcontract average-of-absolutes (values)
   (:in ()
	(assure <list> values)
	(> (length values) 0))		; Not redundant, nil is an instance of <list>.
                                        ; Could have used <cons> instead I guess.
   (:out (res)
	 (assure <integer> res)
	 (>= res 0))
   (quotient (reduce #'+ (map '<list> #'abs values)) (length values)))
;; (average-of-absolutes '(1 3))
;; (average-of-absolutes '())