aboutsummaryrefslogtreecommitdiff
path: root/lib.macros.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-10 07:14:05 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-11 00:40:19 +0000
commitb29855047be9a172d570db71600425b2b06a8a59 (patch)
tree2f09081b3408b516ac417778957b9f6e327442e8 /lib.macros.lisp
parentc5d98886410d46838e5863066edf37e544a72456 (diff)
downloadcantedraw-b29855047be9a172d570db71600425b2b06a8a59.tar.gz
cantedraw-b29855047be9a172d570db71600425b2b06a8a59.tar.bz2
cantedraw-b29855047be9a172d570db71600425b2b06a8a59.zip
Implement `$` operator, second class version of the applicative operator
The `$` operator takes a sequence of FORMS and returns a unary function which applies the input through that sequence via the `->>` operator. For example, consider the predicate "not null". `null` is built into Common Lisp but "not null" requires writing a function (lambda (x) (not (null x))). Now, using this operator, you can write ($ not null) which returns the same lambda as above while being more concise.
Diffstat (limited to 'lib.macros.lisp')
-rw-r--r--lib.macros.lisp6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib.macros.lisp b/lib.macros.lisp
index 5489564..f02e7a2 100644
--- a/lib.macros.lisp
+++ b/lib.macros.lisp
@@ -77,3 +77,9 @@ arguments `LAMBDA-LIST' with body `BODY'."
(declaim (ftype ,type ,name))
(defun ,name ,lambda-list
,@body)))
+
+(defmacro $ (&rest forms)
+ "Given a sequence of FORMS, return a unary function which applies each form
+sequentially"
+ `(lambda (x)
+ (->> x ,@forms)))