Cleaner implementation of DO-FILES.

This commit is contained in:
Brit Butler 2014-04-16 10:46:12 -04:00
parent 13648020c4
commit 7489a6f769

View file

@ -18,13 +18,14 @@ lexically bound to the current subclass' class-name."
(defmacro do-files ((var path &optional extension) &body body)
"For each file on PATH, run BODY. If EXTENSION is provided, only run BODY
on files that match the given extension."
(alexandria:with-gensyms (ext)
`(dolist (,var (cl-fad:list-directory ,path))
,@(if extension
`((let ((,ext (pathname-type ,var)))
(when (and ,ext (string= ,ext ,extension))
,@body)))
`,body))))
(alexandria:with-gensyms (extension-p files)
`(flet ((,extension-p (file)
(string= (pathname-type file) ,extension)))
(let ((,files (cl-fad:list-directory ,path)))
(dolist (,var ,(if extension
`(remove-if-not #',extension-p ,files)
files))
,@body)))))
(defmacro with-current-directory (path &body body)
"Change the current OS directory to PATH and execute BODY in