Created
August 22, 2011 16:44
-
-
Save llibra/1162860 to your computer and use it in GitHub Desktop.
do and multiple values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro do-mvb (var-bindings end-and-result &body body) | |
(let* ((bindings nil) | |
(first-time-p (gensym)) | |
(var-bindings- | |
(reduce (lambda (result binding) | |
(if (consp binding) | |
(destructuring-bind (value . form) binding | |
(cond ((consp value) | |
(push (cons value form) bindings) | |
(append result value)) | |
(t (append result (list binding))))) | |
binding)) | |
var-bindings | |
:initial-value (list `(,first-time-p t nil))))) | |
`(do ,var-bindings- | |
,end-and-result | |
,@(mapcar (lambda (binding) | |
`(if ,first-time-p | |
(multiple-value-setq ,(car binding) ,(cadr binding)) | |
,(if (caddr binding) | |
`(multiple-value-setq ,(car binding) | |
,(caddr binding))))) | |
bindings) | |
,@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment