;;; websearch1.lsp
;;; Some helper code for Assignment 5 in CSE 415, Winter 2004.
;;; S. Tanimoto
;;; This file provides an implementation of a depth-first search
;;; method that starts from a given web page and follows links
;;; to try to find a page that contains a given target string.
;;; In this example, the function FETCH-WEB-PAGE is a simple
;;; simulation that does not actually go to the web.
;;; Code for DFS:
(defun dfs (starting-url goal-string)
(setq open (list starting-url))
(setq closed ())
(tagbody
mainloop
(if (null open) (return-from dfs 'done))
(setq s (pop open))
(if (goalp s goal-string)
(return-from dfs (list 'answer s)) )
(setq L (successors s))
(setq L (remove-all open L))
(setq L (remove-all closed L))
(setq open (append L open))
(push s closed)
(go mainloop)
) )
(defun remove-all (lst1 lst2)
"Returns a copy of LST2 from which all
elements of LST1 have been removed."
(cond ((null lst1) lst2)
(t (remove-all
(cdr lst1)
(remove (car lst1) lst2 :test #'equal) ))
) )
(defun goalp (url goal-string)
(if (not (equal url *current-url*))
(progn
(setq *page* (fetch-web-page url))
(setq *current-url* url) ) )
(search goal-string *page*) )
;;; The following function is a kind of scaffolding for the
;;; rest of the program. It simulates fetching web pages,
;;; but it doesn't really go out onto the web.
(defun fetch-web-page (url)
(cond
((equal url "www.site1.com")
"Page 1: blah blah ")
((equal url "www.site2.com")
"Page 2: blah blah ")
((equal url "www.site3.com")
"Page 3: blah blah Ides of March ")
) )
(defun successors (url)
(if (not (equal url *current-url*))
(progn (setq *page* (fetch-web-page url))
(setq *current-url* url) ) )
(setq *temp* *page*)
(succ-helper) )
(defun succ-helper ()
"Uses what's left of the *PAGE* value most recently retrieved."
(let* ((marker "