From 92cd04b4242dd8cf47237569a662a6791de0360b Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 9 Mar 2023 18:42:39 -0800 Subject: Add docstring to with-env --- hyperquirks.lisp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'hyperquirks.lisp') diff --git a/hyperquirks.lisp b/hyperquirks.lisp index 70584a5..8fdbe54 100644 --- a/hyperquirks.lisp +++ b/hyperquirks.lisp @@ -5,11 +5,20 @@ ;;; MACROS (defmacro with-env ((&rest bindings) &body body) + "Execute BODY in context where environment variables are bound to +particular values. When BODY finishes executing, or exits early, the +environment variables are restored to their original values. + +EXAMPLE: + +(with-env ((\"VAR1\" (get-value-for-var)) + (\"VAR2\" \"SOME_VAL\")) + (do-stuff-with-environment))" (let ((bindings (loop :for binding :in bindings :collect (list* (gensym "VAR") (gensym "VAL") binding)))) `(let* ,(loop :for (oldval cacheval envvar newval) :in bindings - :collect `(,oldval (uiop:getenv ,envvar)) + :collect `(,oldval (or (uiop:getenv ,envvar) "")) :collect `(,cacheval ,newval)) (setf ,@(loop :for (oldval cacheval envvar newval) :in bindings :collect `(uiop:getenv ,envvar) -- cgit v1.2.3