Skip to content

Instantly share code, notes, and snippets.

@jchros
Last active April 18, 2021 13:11
Show Gist options
  • Select an option

  • Save jchros/d6573e39df554025cfe4abf87dc7dcdf to your computer and use it in GitHub Desktop.

Select an option

Save jchros/d6573e39df554025cfe4abf87dc7dcdf to your computer and use it in GitHub Desktop.

Revisions

  1. jchros revised this gist Apr 18, 2021. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions valsetf.lisp
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,14 @@
    (defmacro valsetf (values-form . places)
    "Assigns the values of VALUES-FORM to the given 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 *))
    (gensyms (mapcar #'(lambda (_)
    (declare (ignore _))
    (gensym "VALUE"))
    places)))
    `(multiple-value-bind ,gensyms ,values-form
  2. jchros created this gist Apr 17, 2021.
    10 changes: 10 additions & 0 deletions valsetf.lisp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    (defmacro valsetf (values-form . places)
    "Assigns the values of VALUES-FORM to the given PLACES."
    (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)))))