aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-11-30 19:03:48 -0800
committercolin <colin@cicadas.surf>2023-11-30 19:03:48 -0800
commit68d27225b47bf85be43a8a33e619b61486e55ca2 (patch)
treee1bf751320e7cb77986b7e5775b07b19c004bc4d
parent6313c32898f155c44fff350aa18358be58483fd9 (diff)
More name refinementHEADmain
-rw-r--r--README.org10
-rw-r--r--terrafirma.lisp4
2 files changed, 7 insertions, 7 deletions
diff --git a/README.org b/README.org
index 4fe65a2..690f053 100644
--- a/README.org
+++ b/README.org
@@ -2,7 +2,7 @@
Terrafirma is a small system for defining data type validators that produce nice error messages on invalid data.
-Terrafirma's main export is the =DEFVALIDATOR= macro. This macro defines a validator function. The body of the validator function evalutes in a special context. Within this context, the symbol =VALIDATE= is a macro that can be used to check predicates and singal a =VALIDATION-ERROR= upon failure: basically just a wrapper around =ASSERT=.
+Terrafirma's main export is the =DEFINE-VALID= macro. This macro defines a validator function. The body of the validator function evalutes in a special context. Within this context, the symbol =VALIDATE= is a macro that can be used to check predicates and singal a =VALIDATION-ERROR= upon failure: basically just a wrapper around =ASSERT=.
The real "magic" happens when validation functions are defined in terms of other validation functions. In that case, validation errors are nested to produce highly-specific messages for your validation error.
@@ -21,7 +21,7 @@ Here is an example:
;; defines a function called VALID-POINT-P. By default the name of the
;; type is used to create the validator function's name.
-(defvalidator point (pt)
+(define-valid point (pt)
(validate (and (slot-boundp pt 'x) (slot-boundp pt 'y))
"Both X and Y must be bound.")
(with-slots (x y) pt
@@ -32,9 +32,9 @@ Here is an example:
((verts :initarg :verts :type (cons point))))
;; defines a function called VALID-POLY-P. Here we pass a specific
-;; name in. We also define this validator in terms of gthe
+;; name in. We also define this validator in terms of the
;; VALID-POLY-P validator.
-(defvalidator polygon (p :name valid-poly-p)
+(define-valid polygon (p :name valid-poly-p)
(validate (slot-boundp p 'verts) "VERTS must be bound.")
(let ((verts (slot-value p 'verts)))
(validate (< 2 (length verts)) "VERTS must contain at least three points.")
@@ -68,4 +68,4 @@ Now, call =VALID-POLY-P= on a couple of bad polygons.
-See the docstring on =DEFVALIDATOR= for use details.
+See the docstring on =DEFINE-VALID= for use details.
diff --git a/terrafirma.lisp b/terrafirma.lisp
index e5a3ec5..212f7cd 100644
--- a/terrafirma.lisp
+++ b/terrafirma.lisp
@@ -5,7 +5,7 @@
(:export
#:validation-error ; Condition
#:validate ; Macrolet Symbol
- #:defvalidator ; Macro
+ #:define-valid ; Macro
))
(in-package #:terrafirma)
@@ -48,7 +48,7 @@
(defvar *type*)
(defvar *instance*)
-(defmacro defvalidator (type (var &key name) &body body)
+(defmacro define-valid (type (var &key name) &body body)
"Defines a validation function. If TYPE is a symbolic type identifier,
then the defined function will have a name like VALID-<TYPE>-P.
Otherwise a NAME must be provided.