Skip to content

Instantly share code, notes, and snippets.

@jchros
Last active April 18, 2021 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchros/d6573e39df554025cfe4abf87dc7dcdf to your computer and use it in GitHub Desktop.
Save jchros/d6573e39df554025cfe4abf87dc7dcdf to your computer and use it in GitHub Desktop.
(defmacro valsetf (values-form . places)
"Assigns the values of VALUES-FORM to the given PLACES.
If VALUES-FORM yields more values than there are fields in PLACES, the
remaining values are discarded. If there are more fields in PLACES
than there are values returned by the VALUES-FORM, the remaining
fields are initialized to NIL."
(assert places)
(let* ((*gensym-counter* 1)
(gensyms (mapcar #'(lambda (_)
(declare (ignore _))
(gensym "VALUE"))
places)))
`(multiple-value-bind ,gensyms ,values-form
(setf ,@(mapcan #'list places gensyms)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment