;; figure 3.12 (defun shortest-path (start end net) (bfs end (list (list start)) net )) (defun bfs (end queue net) (if (null queue) nil (let ((path (car queue))) ; this will be list (let ((treenode (car path))) ; car of the list (if (eql treenode end) ; if t we've found a shortest path (could be more) (reverse path) ; path built from cons, need to reverse (bfs end (append (cdr queue) (new-paths path treenode net)) net)))))) (defun new-paths (path treenode net) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc treenode net)))) ; find other nodes we can reach from node (deftest test-binary-search() (let ((net '((a b c) (b c) (c d)))) (check (equal '(a c d) (shortest-path 'a 'd net)))))