summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-07-09 13:55:04 -0700
committercolin <colin@cicadas.surf>2023-07-09 13:55:04 -0700
commit704d96bb21ba1aaadb18d6c7b12fbd6da8554174 (patch)
treef8156227ff67982d4fee94fd9cc190dbc0c42c3c
parent906b01d476d882ab00f56fc220945b24a454083f (diff)
Add: nicer >> form called >>>
-rw-r--r--hyperquirks.lisp18
-rw-r--r--package.lisp1
2 files changed, 18 insertions, 1 deletions
diff --git a/hyperquirks.lisp b/hyperquirks.lisp
index d64ce08..7b6da14 100644
--- a/hyperquirks.lisp
+++ b/hyperquirks.lisp
@@ -150,7 +150,18 @@ form. When they do, the value of the previous form is passed into all
instances is substituted in.
However, two different substitution variables CANNOT APPEAR in a
-single pipe form."
+single pipe form.
+
+This macro accepts additional syntax: the :? form standing on its own
+indicates the the next form shold be a predicate that, if it evaluates
+to NIL, causes an early exit, with failure state FAIL.
+
+E.g.
+
+(>> (:fail :oh-no!)
+ (random 10) ; start with a random number
+ :? evenp ; exit with :oh-no! unless even
+ (+ 10 _)) ; add 10 and return."
(let ((prefix
(etypecase prefix
(string prefix)
@@ -158,6 +169,7 @@ single pipe form."
(labels ((var-p (v)
"A variable is a symbol that starts with PREFIX"
(and (symbolp v)
+ (<= (length prefix) (length (symbol-name v)))
(string= prefix (symbol-name v) :end2 (length prefix))))
(pipe-form-p (form)
"A pipe form is either a symbol or a tree that contains
@@ -211,6 +223,10 @@ single pipe form."
(list 'block block
(reduce #'folder (escape-early-transform pipe-forms) :initial-value initform)))))
+
+(defmacro >>> (initform &rest pipe-forms)
+ `(>> () ,initform ,@pipe-forms))
+
(defmacro binding-cond (&body clauses)
"Like cond except the first form of every clause is a binding form
alá IMPERATIVE.
diff --git a/package.lisp b/package.lisp
index 5025869..141b53e 100644
--- a/package.lisp
+++ b/package.lisp
@@ -6,6 +6,7 @@
(:export
#:with-env
#:>>
+ #:>>>
#:let+
#:imperative
#:binding-cond