Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructive versions of threading macros #300

Open
Luis-Henriquez-Perez opened this issue May 12, 2019 · 5 comments
Open

Destructive versions of threading macros #300

Luis-Henriquez-Perez opened this issue May 12, 2019 · 5 comments

Comments

@Luis-Henriquez-Perez
Copy link

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))
@Luis-Henriquez-Perez
Copy link
Author

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)))

@cireu
Copy link
Contributor

cireu commented Aug 11, 2019

Why not use cl-callf?

@Fuco1
Copy link
Collaborator

Fuco1 commented Aug 13, 2019

I tried

(let (var)
  (cl-callf '->> var 1 (* 2) (+ 1))
  var)

and I get Debugger entered--Lisp error: (invalid-function '->>)

@cireu
Copy link
Contributor

cireu commented Aug 13, 2019 via email

@Fuco1
Copy link
Collaborator

Fuco1 commented Aug 13, 2019

I see, yes that works. I like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants