a996dd9ad3eb

Add `_`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 11 Dec 2019 18:51:49 -0500
parents b839a83bbf2e
children 164b3e41c13b
branches/tags (none)
files package.lisp src/control-flow.lisp

Changes

--- a/package.lisp	Fri Dec 06 21:00:13 2019 -0500
+++ b/package.lisp	Wed Dec 11 18:51:49 2019 -0500
@@ -177,6 +177,7 @@
   (:export
     :-<>
     :<>
+    :_
     :nest
     :recursively
     :recur
--- a/src/control-flow.lisp	Fri Dec 06 21:00:13 2019 -0500
+++ b/src/control-flow.lisp	Wed Dec 11 18:51:49 2019 -0500
@@ -13,6 +13,19 @@
                     forms))
      <>))
 
+(defmacro _ (expr &rest forms)
+  "Thread the given forms, with `_` as a placeholder."
+  ;; I am going to lose my fucking mind if I have to program lisp without
+  ;; a threading macro, but I don't want to add another dep to this library, so
+  ;; here we are.
+  `(let* ((_ ,expr)
+          ,@(mapcar (lambda (form)
+                      (if (symbolp form)
+                        `(_ (,form _))
+                        `(_ ,form)))
+                    forms))
+     _))
+
 (defmacro nest (&rest forms)
   "Thread the given forms, putting each as the body of the previous.