(with-answer (painter ?x ?y ?z) (format t "~A ~A is a painter.~%" ?y ?x)) is expanded by the query interpreter into: (dolist (#:g1 (interpret-query '(painter ?x ?y ?z))) (let ((?x (binding '?x #:g1)) (?y (binding '?x #:g1)) (?z (binding '?x #:g1))) (format t "~A ~A is a painter.~%" ?y ?x))) and by the query compiler into: (with-gensyms (?x ?y ?z) (dolist (#:g1 (db-query 'painter)) (pat-match (?x ?y ?z) #:g1 (progn (format t "~A ~A is a painter.~%" ?y ?x)) nil)))