;; The recursive search example with association lists for ;; representing the graph. (setf s '((neighbors (a d)) (coordinates (0 3)))) (setf a '((neighbors (s b d)) (coordinates (4 6)))) (setf b '((neighbors (a c e)) (coordinates (7 6)))) (setf c '((neighbors (b)) (coordinates (11 6)))) (setf d '((neighbors (s a e)) (coordinates (3 0)))) (setf e '((neighbors (b d f)) (coordinates (6 0)))) (setf f '((neighbors (e)) (coordinates (11 3)))) (defun breadth-first (start finish &optional (queue (list (list start)))) (cond ((endp queue) nil) ((equal finish (first (first queue))) (reverse (first queue))) (t (breadth-first start finish (append (rest queue) (extend (first queue))))))) (defun extend (path) (print (reverse path)) (mapcar #'(lambda (new-node) (cons new-node path)) (remove-if #'(lambda (neighbor) (member neighbor path)) (second (assoc 'neighbors (eval (first path)))))))