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) (defmacro do-files ((var path &optional extension) &body body)
"For each file on PATH, run BODY. If EXTENSION is provided, only run BODY "For each file on PATH, run BODY. If EXTENSION is provided, only run BODY
on files that match the given extension." on files that match the given extension."
(alexandria:with-gensyms (ext) (alexandria:with-gensyms (extension-p files)
`(dolist (,var (cl-fad:list-directory ,path)) `(flet ((,extension-p (file)
,@(if extension (string= (pathname-type file) ,extension)))
`((let ((,ext (pathname-type ,var))) (let ((,files (cl-fad:list-directory ,path)))
(when (and ,ext (string= ,ext ,extension)) (dolist (,var ,(if extension
,@body))) `(remove-if-not #',extension-p ,files)
`,body)))) files))
,@body)))))
(defmacro with-current-directory (path &body body) (defmacro with-current-directory (path &body body)
"Change the current OS directory to PATH and execute BODY in "Change the current OS directory to PATH and execute BODY in