aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-09 16:09:48 -0600
committerColin Okay <okay@toyful.space>2022-02-09 16:09:48 -0600
commitaec0893df2f4bb8fa8da7c71cb8dca09c0bd5f86 (patch)
treea6b66f1b816aec9eaa408996b8b985354c221be9
parent60b736fc09bc7116a60dd98c0f7d31b2d6bb79d5 (diff)
defined map-parameters
-rw-r--r--lazybones.lisp17
-rw-r--r--package.lisp1
2 files changed, 18 insertions, 0 deletions
diff --git a/lazybones.lisp b/lazybones.lisp
index 2b28be7..5ccbf6f 100644
--- a/lazybones.lisp
+++ b/lazybones.lisp
@@ -379,6 +379,23 @@ of each NAME, or NIL if there is no such parameter."
collect `(,name (cdr (assoc ,string-name ,params :test #'string-equal))))
,@body))))
+(defmacro map-parameters ((&rest params) &body body)
+ "PARAMS is a list of pairs (NAME PARSER). MAP-PARAMETERS behaves
+exactly like LET-PARAMETERS except that the values boudn to NAMEs are
+first mapped with the PARSER function."
+ (assert (loop for (name parser) in params
+ always (and (symbolp name)
+ (or (symbolp parser) (functionp parser))))
+ ()
+ "Malformed PARAMS in MAP-PARAMETERS macro")
+
+ (let ((names (mapcar #'car params)))
+ `(let-parameters ,names
+ (let ,(loop for name in names
+ collect `(,name (when ,name (funcall ',(second (assoc name params)) ,name))))
+ ,@body))))
+
+
(defun http-ok (content)
"Content should be a string, a byte-vector, or a pathname to a local
file. CONTENT-TYPE should be a MIME type string."
diff --git a/package.lisp b/package.lisp
index 64b0649..1e7965e 100644
--- a/package.lisp
+++ b/package.lisp
@@ -52,6 +52,7 @@
#:defendpoint*
#:endpoint
#:let-parameters
+ #:map-parameters
#:http-err
#:http-ok
#:http-respond