aboutsummaryrefslogtreecommitdiff
path: root/lazybones.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lazybones.lisp')
-rw-r--r--lazybones.lisp17
1 files changed, 17 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."