From 032fb6578034edfef58d8392c4c9b468437b21c8 Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Sun, 7 Feb 2021 00:53:13 +0000 Subject: Fix DBC for eisl --- dbc2.lsp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/dbc2.lsp b/dbc2.lsp index 477dc38..6d29596 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 reduce (function sequence) ;; (let ((res 0)) ;; (for ((xs sequence (cdr xs))) @@ -13,11 +16,13 @@ (setq res (+ res (car xs)))))) (defun average-of-absolutes (values) (the values) - (unless (> (length values) 0) - (error "average-of-absolutes requires non-null list" values)) + ;; (unless (> (length values) 0) + ;; (error "average-of-absolutes requires non-null list" values)) + (assert (> (length values) 0)) (let ((res (quotient (sum values) (length values)))) - (unless (>= res 0) - (error "average-of-absolutes must ensure positive result" res)) - (the res))) + ;; (unless (>= res 0) + ;; (error "average-of-absolutes must ensure positive result" res)) + (assert (>= res 0)) + (the res))) ;; (average-of-absolutes '(1 3)) ;; (average-of-absolutes '()) -- cgit 1.4.1-2-gfad0 From 922f146dfa960052ca94200a1645c5c30aa40b63 Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Thu, 25 Feb 2021 12:47:54 +0000 Subject: DbC for eisl --- dbc2.lsp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dbc2.lsp b/dbc2.lsp index 6d29596..224bb1e 100644 --- a/dbc2.lsp +++ b/dbc2.lsp @@ -16,12 +16,10 @@ (setq res (+ res (car xs)))))) (defun average-of-absolutes (values) (the 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)) + ;; must ensure positive result (assert (>= res 0)) (the res))) ;; (average-of-absolutes '(1 3)) -- cgit 1.4.1-2-gfad0