;;;; Anti Bugging Tools ;Adam nelson ;Chet Tobrey (defun eat-porridge (bear) "assertion for three bears with differing porridge temperature needs" (assert (< too-cold (temperatue (bear-porridge bear)) too-hot) (bear (bear-porridge bear)) "~a's porridge is not just right: ~a" bear (hotness (bear-porridge bear))) (eat (bear-porridge bear))) (egs :3.14 (eg '(defun average (numbers) (if (null numbers) (progn (cerror "Use 0 as the Average." "Average of empty list is undefined.") 0) (/ (reduce #'+ numbers) (length numbers)))) :of "the function average with a continuable error defined within. You can also specify an error but that would kill the example" :out 'AVERAGE) (eg '(average '()) :of "calling the average function on an empty list" :out '0 ) (eg '(defun sqr (x) "multiply x by itself" (check-type x number) (* x x)) :of "using check-type. if sqr is called with a non number argument, an appropriate error message is printed" ) (eg '(sqr "jello") :of "calling square with a non-number argument") (eg '(defun times-two (x) "multiple x by two" (assert (numberp x)(x)) (* x 2)) :of "another finction times-two that uses assert (numberp x)(x) to check if argument is a number and giving a value to change in the event of an error") (eg '(times-two '(How are You?)) :of "calling times-two with a list instead of a number") ;TIMING TOOLS (eg '(defun f (n)(dotimes (i n) nil)) :of "a function we will time" :out 'F) (eg '(time (f 100000)) :of "timing the function wtih the time function" :out 'NIL) (eg '(compile 'f) :of "compiling f" :out 'F) (eg '(time (f 100000)) :of "timing the compiled function" :out 'NIL))