summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-03-09 18:35:35 -0800
committercolin <colin@cicadas.surf>2023-03-09 18:35:35 -0800
commit883b6940495692df570093165e33610597b22c33 (patch)
tree898d002673682242ce5604ba4b5bc481ab9c53df
parentb905aeb158fd19ccf5ec78d8f7b2ea23767e6af1 (diff)
Add: with-env
-rw-r--r--hyperquirks.lisp27
-rw-r--r--package.lisp1
2 files changed, 28 insertions, 0 deletions
diff --git a/hyperquirks.lisp b/hyperquirks.lisp
index f0e8bfc..70584a5 100644
--- a/hyperquirks.lisp
+++ b/hyperquirks.lisp
@@ -4,6 +4,21 @@
;;; MACROS
+(defmacro with-env ((&rest bindings) &body body)
+ (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 `(,cacheval ,newval))
+ (setf ,@(loop :for (oldval cacheval envvar newval) :in bindings
+ :collect `(uiop:getenv ,envvar)
+ :collect cacheval))
+ (unwind-protect (progn ,@body)
+ ,@(loop :for (oldval cacheval envvar newval) :in (reverse bindings)
+ :collect `(when ,oldval
+ (setf (uiop:getenv ,envvar) ,oldval)))))))
+
(defmacro let+ (bindings &body body)
"General purpose binding. Normal let bindings, destructuring-binds,
and multiple-value-binds all in the same form.
@@ -86,6 +101,16 @@ returned from.
`(block () ,@(expander body))))
+(defmacro $> (input-form &rest functions)
+ (loop :with sub = input-form
+ :for next-form :in piped-to-forms
+ :when (symbolp next-form)
+ :do (setf sub `(funcall ,next-form ,sub))
+ :when (consp next-form)
+ :do (setf sub `(,(first next-form) ,sub ,@(rest next-form)))
+ :finally (return sub )))
+
+
(defmacro binding-cond (&body clauses)
"Like cond except the first form of every clause is a binding form
alá IMPERATIVE.
@@ -148,3 +173,5 @@ E.g.
+
+
diff --git a/package.lisp b/package.lisp
index f3b157c..342dbbf 100644
--- a/package.lisp
+++ b/package.lisp
@@ -4,6 +4,7 @@
(:use #:cl)
(:nicknames #:hq)
(:export
+ #:with-env
#:let+
#:imperative
#:binding-cond