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

ssetf #4

Open
ghost opened this issue Dec 15, 2015 · 2 comments
Open

ssetf #4

ghost opened this issue Dec 15, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 15, 2015

Often, I want to refer to the place I'm setting with an anaphora. The code to do this is as follows:

(defmacro ssetf (&rest bindings)
  "Anaphoric setf that binds it to a symbol-macro evaluating to name."
  `(progn
     ,@(loop for (name val &rest _) on bindings by #'cddr
             collect
             `(symbol-macrolet ((it ,name))
                (setf it ,val)))))
@tokenrove
Copy link
Collaborator

My initial thought is that most uses of this would probably be better done with a modify macro. Is there a compelling example for ssetf?

@noctuid
Copy link

noctuid commented May 1, 2018

This article has some good examples (I think) of a somewhat similar macro called zapf (modified to use it):

(defmacro zapf (place expr)
  (multiple-value-bind
        (temps exprs stores store-expr access-expr)
      (get-setf-expansion place)
    `(let* (,@(mapcar #'list temps exprs)
            (,(car stores)
              (let ((it ,access-expr))
                ,expr)))
       ,store-expr)))

(defun move-ball (ball distance screen-width)
  (zapf (ball-x ball)
        (mod (+ distance it) screen-width)))

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

2 participants