about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDarren Bane <darren.bane@emdalo.com>2021-02-25 12:49:42 +0000
committerDarren Bane <darren.bane@emdalo.com>2021-02-25 12:49:42 +0000
commit123757e1122ff19925671325f95e94b145d91e31 (patch)
tree7a110aea888d922e3c716f46222e788cd78e9142
parent06c451e39ff50b7646f4aa99efae67e0d4850a5f (diff)
parent922f146dfa960052ca94200a1645c5c30aa40b63 (diff)
downloadlsp-123757e1122ff19925671325f95e94b145d91e31.tar.gz
Merge branch 'master' of tilde.institute:public_repos/lsp
-rw-r--r--dbc2.lsp15
1 files changed, 9 insertions, 6 deletions
diff --git a/dbc2.lsp b/dbc2.lsp
index 21089ba..657d297 100644
--- a/dbc2.lsp
+++ b/dbc2.lsp
@@ -1,5 +1,8 @@
 (defmacro unless (test :rest body)
-  `(if (not ,test) (progn ,@body)))
+   `(if (not ,test) (progn ,@body)))
+(defmacro assert (test)
+   `(unless ,test
+            (error "assert: value is false." ',test)))
 (defun sum (sequence)
   (let ((res 0))
     (for ((xs sequence (cdr xs)))
@@ -7,11 +10,11 @@
       (setq res (+ res (car xs))))))
 (defun average-of-absolutes (values)
   (the <list> values)
-  (unless (> (length values) 0)
-    (error "average-of-absolutes requires non-null list" values))
+  ;; requires non-null list
+  (assert (> (length values) 0))
   (let ((res (quotient (sum values) (length values))))
-    (unless (>= res 0)
-      (error "average-of-absolutes must ensure positive result" res))
-    (the <fixnum> res)))
+       ;; must ensure positive result
+       (assert (>= res 0))
+       (the <fixnum> res)))
 ;; (average-of-absolutes '(1 3))
 ;; (average-of-absolutes '())