aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--terrafirma.lisp31
1 files changed, 15 insertions, 16 deletions
diff --git a/terrafirma.lisp b/terrafirma.lisp
index 16938ee..62d063c 100644
--- a/terrafirma.lisp
+++ b/terrafirma.lisp
@@ -46,26 +46,25 @@
(defvar *type*)
(defvar *instance*)
-(defmacro validate (check msg &rest args)
- (let ((suberr (gensym)))
- `(prog1 t
- (let (,suberr)
- (assert (handler-case ,check (validation-error (sub) (setf ,suberr sub) nil))
- () 'terrafirma::validation-error
- :type terrafirma::*type*
- :instance terrafirma::*instance*
- :reason (format nil ,msg ,@args)
- :suberror ,suberr)))))
-
-
(defmacro defvalidator ((var type &key name) &body body)
(assert (and var (symbolp var)) (var) "VAR must be a symbol.")
(let ((validator-name
(cond ((and name (symbolp name)) name)
- ((symbolp type) (intern (format nil "VALIDATE-~a" type)))
+ ((symbolp type) (intern (format nil "VALIDATED-~a" type)))
(t (error "Validator Name: Either TYPE must be a symbol or a NAME must be provided.")))))
`(defun ,validator-name (,var)
- (let ((terrafirma::*type* ',type)
- (terrafirma::*instance* ',var))
- ,@body))))
+ (macrolet ((validate (check msg &rest args)
+ (let ((suberr (gensym)))
+ `(prog1 t
+ (let (,suberr)
+ (assert (handler-case ,check (validation-error (sub) (setf ,suberr sub) nil))
+ () 'terrafirma::validation-error
+ :type terrafirma::*type*
+ :instance terrafirma::*instance*
+ :reason (format nil ,msg ,@args)
+ :suberror ,suberr))))))
+
+ (let ((terrafirma::*type* ',type)
+ (terrafirma::*instance* ,var))
+ ,@body)))))