aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 16:34:15 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 16:34:15 +0000
commitf8a834c0d24b1c57f14e9f86ec827aad73e4473e (patch)
treed0a7084400269e42abb9beef2a1a7ed94c22ddbf
parent02ff1a3fb3f687160b3164680fd655da56c0eae9 (diff)
downloadcantedraw-f8a834c0d24b1c57f14e9f86ec827aad73e4473e.tar.gz
cantedraw-f8a834c0d24b1c57f14e9f86ec827aad73e4473e.tar.bz2
cantedraw-f8a834c0d24b1c57f14e9f86ec827aad73e4473e.zip
Rewrote --> to take a placeholder symbol as first argument
Instead of exporting cantedraw.lib.macro._ and making anyone who wants to use the --> macro _require_ importing that specific symbol, let's just make it so the user has to supply a placeholder name before they do anything. This means each package provides its own placeholder symbol which lowers coupling.
-rw-r--r--lib.macros.lisp20
-rw-r--r--main.lisp7
-rw-r--r--packages.lisp2
3 files changed, 15 insertions, 14 deletions
diff --git a/lib.macros.lisp b/lib.macros.lisp
index f2435d4..70f5917 100644
--- a/lib.macros.lisp
+++ b/lib.macros.lisp
@@ -19,31 +19,31 @@
(in-package :cantedraw.lib.macros)
-(defmacro --> (&rest forms)
- "Lexically bind current form as `_' for use in the next form, returning the
- result of the last form.
+(defmacro --> (placeholder &body forms)
+ "Lexically bind current form as `placeholder' for use in the next form, returning
+the result of the last form.
i.e.
(--> (a1 a2...) (b1 b2...) (c1 c2...)) =
-(let* ((_ (a1 a2 ...))
- (_ (b1 b2 ...))
- (_ (c1 c2 ...)))
+(let* ((placeholder (a1 a2 ...))
+ (placeholder (b1 b2 ...))
+ (placeholder (c1 c2 ...)))
_ )
Also includes transformer where symbols are considered unary functions i.e.
-(--> x y) <-> (--> x (y _)).
+(--> x y) <-> (--> x (y placeholder)).
"
(if (null forms)
nil
(let ((assignment-forms
(loop :for f :in forms
:for canon-f := (if (symbolp f)
- (list f 'cantedraw.lib.macros:_)
+ (list f placeholder)
f)
- :collect `(cantedraw.lib.macros:_ ,canon-f))))
+ :collect `(,placeholder ,canon-f))))
`(let* ,assignment-forms
- cantedraw.lib.macros:_))))
+ ,placeholder))))
(defmacro ->> (&rest forms)
"Make current form the last argument of the next form, returning the last
diff --git a/main.lisp b/main.lisp
index af6312d..2bd3102 100644
--- a/main.lisp
+++ b/main.lisp
@@ -44,6 +44,7 @@
inp))
(defun start ()
- (--> (read-until-integers)
- (cons '+ _)
- (format t "~a = ~a~%" _ (eval _))))
+ (--> var
+ (read-until-integers)
+ (cons '+ var)
+ (format t "~a = ~a~%" var (eval var))))
diff --git a/packages.lisp b/packages.lisp
index 24de212..56d3727 100644
--- a/packages.lisp
+++ b/packages.lisp
@@ -20,7 +20,7 @@
(defpackage cantedraw.lib.macros
(:use :cl)
(:export
- :_ :--> :->>
+ :--> :->>
:-> :fn
:while :alist-val
:$))