Skip to content

Instantly share code, notes, and snippets.

@kurohuku
Created August 31, 2010 01:19
Show Gist options
  • Save kurohuku/558364 to your computer and use it in GitHub Desktop.
Save kurohuku/558364 to your computer and use it in GitHub Desktop.
(defmacro with-assoc-values (binds alist &body body)
(let ((al (gensym "alist")))
(flet ((expand-bind (bind)
`(,(first bind)
(cdr (assoc ,(second bind) ,al)))))
`(let ((,al ,alist))
(let ,(mapcar #'expand-bind binds)
,@body)))))
;; (with-assoc-values ((a :hoge) (b :fuga)) `((:hoge . (3 4)) (:fuga . 4))
;; (list a b))
;; => ((3 4) 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment