about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDarren Bane <dbane@tilde.institute>2021-05-14 23:42:35 +0100
committerDarren Bane <dbane@tilde.institute>2021-05-14 23:42:35 +0100
commit0c2561d21d59254669dea0b662946d82fcc7c50c (patch)
tree3b3be00c0166c51d227b41ff191db09afa31074d
parenta4ab4320c2f3350faf9b1854eaee5ecce6bcf1b3 (diff)
downloadlsp-0c2561d21d59254669dea0b662946d82fcc7c50c.tar.gz
Update DbC
-rw-r--r--dbc2.lsp17
1 files changed, 8 insertions, 9 deletions
diff --git a/dbc2.lsp b/dbc2.lsp
index 552bc44..5a2699d 100644
--- a/dbc2.lsp
+++ b/dbc2.lsp
@@ -1,20 +1,19 @@
-(defmacro unless (test :rest body)
-   `(if (not ,test) (progn ,@body)))
+(import "macro")                        ; For unless
 (defmacro assert (test)
-   `(unless ,test
-            (error "assert: value is false." ',test)))
-(defun sum (sequence)
+  `(unless ,test
+     (error "assert: value is false." ',test)))
+(defun my-sum (sequence)
   (let ((res 0))
     (for ((xs sequence (cdr xs)))
-      ((null xs) res)
-      (setq res (+ res (car xs))))))
+         ((null xs) res)
+         (setq res (+ res (car xs))))))
 (defun average-of-absolutes (values)
   (assure <list> values)
   ;; requires non-null list
   (assert (> (length values) 0))
-  (let ((res (quotient (sum (mapcar #'abs values)) (length values))))
+  (let ((res (quotient (my-sum (mapcar #'abs values)) (length values))))
        ;; must ensure positive result
        (assert (>= res 0))
-       (assure <float> res)))
+       (assure <number> res)))
 ;; (average-of-absolutes '(1 3))
 ;; (average-of-absolutes '())