dash.el
dash.el copied to clipboard
Destructive versions of threading macros
Very often I want to update the value of a variable using a threading macro.
(setq cute-var (->> cute-var (form1) (form2) ...))
So often in fact that the setq cute-var var is beginning to feel tedious and unnecessary. I suspect I'm not the only one. Perhaps creating destructive versions of these macros would be helpful. What do you think?
(->>* cute-var (form1) (form2))
Here are some of my implementations. They seem trivial. If you're interested in this idea and want me to make a formal pull request let me know and I'll do so.
(defmacro ->* (x &rest forms)
`(setq ,x (-> ,x ,@forms)))
(defmacro ->>* (x &rest forms)
`(setq ,x (->> ,x ,@forms)))
(defmacro -->* (x &rest forms)
`(setq ,x (--> ,x ,@forms)))
Why not use cl-callf?
I tried
(let (var)
(cl-callf '->> var 1 (* 2) (+ 1))
var)
and I get Debugger entered--Lisp error: (invalid-function '->>)
On Tue, 13 Aug 2019 23:20:30 +0800, Matus Goljer wrote:
[1 <text/plain; UTF-8 (7bit)>] [2 <text/html; UTF-8 (7bit)>] I tried
(let (var) (cl-callf '->> var 1 (* 2) (+ 1)) var)
and I get Debugger entered--Lisp error: (invalid-function '->>)
― You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
(cl-callf '->> var (* 2) (+ 1)) is wrong usage, you should use
(let ((var 1)) (cl-callf ->> var (* 2) (+ 1)))
I see, yes that works. I like it.