# HG changeset patch # User Steve Losh # Date 1460993882 0 # Node ID fb3a334a14f312cffc6d5c9f4e40891e69189458 # Parent e45304805b40561de485ff6b78e919e3597ff39f Refactor the shared variables copypasting diff -r e45304805b40 -r fb3a334a14f3 src/wam/compiler.lisp --- a/src/wam/compiler.lisp Mon Apr 18 15:29:53 2016 +0000 +++ b/src/wam/compiler.lisp Mon Apr 18 15:38:02 2016 +0000 @@ -609,12 +609,13 @@ (defun find-shared-variables (terms) "Return a list of all variables shared by two or more terms." (let* ((variables (remove-duplicates (tree-collect #'variable-p terms)))) - (flet ((permanent-p (variable) - "Permanent variables are those contained in more than 1 term." - (> (count-if (curry #'tree-member-p variable) - terms) - 1))) - (remove-if-not #'permanent-p variables)))) + (labels + ((count-uses (variable) + (count-if (curry #'tree-member-p variable) + terms)) + (shared-p (variable) + (> (count-uses variable) 1))) + (remove-if-not #'shared-p variables)))) (defun find-permanent-variables (clause) "Return a list of all the 'permanent' variables in `clause`.