From: Mark Wooding Date: Sat, 3 Aug 2019 14:01:14 +0000 (+0100) Subject: src/utilities.lisp (categorize): Don't leak the ITEMS-VAR into the body. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/64a7e6515e1e585b420c1c14acda9be9ff84c3db src/utilities.lisp (categorize): Don't leak the ITEMS-VAR into the body. The body forms only need the CAT-VARs, so that's all that should be bound in their environment. --- diff --git a/src/utilities.lisp b/src/utilities.lisp index 4935f8b..769ff5d 100644 --- a/src/utilities.lisp +++ b/src/utilities.lisp @@ -651,16 +651,17 @@ (defmacro categorize ((itemvar items &key bind) categories &body body) (symbol-name name) "-"))) cat-names)) (items-var (gensym "ITEMS-"))) - `(let ((,items-var ,items) - ,@(mapcar (lambda (cat-var) (list cat-var nil)) cat-vars)) - (dolist (,itemvar ,items-var) - (let* ,bind - (cond ,@(mapcar (lambda (cat-match-form cat-var) - `(,cat-match-form - (push ,itemvar ,cat-var))) - cat-match-forms cat-vars) - ,@(and (not (member t cat-match-forms)) - `((t (error "Failed to categorize ~A" ,itemvar))))))) + `(let (,@(mapcar (lambda (cat-var) (list cat-var nil)) cat-vars)) + (let ((,items-var ,items)) + (dolist (,itemvar ,items-var) + (let* ,bind + (cond ,@(mapcar (lambda (cat-match-form cat-var) + `(,cat-match-form + (push ,itemvar ,cat-var))) + cat-match-forms cat-vars) + ,@(and (not (member t cat-match-forms)) + `((t (error "Failed to categorize ~A" + ,itemvar)))))))) (let ,(mapcar (lambda (name var) `(,name (nreverse ,var))) cat-names cat-vars)