This is an overview of the implementation of the search module; hopefully, it will help you understand the actual code. The description is arranged for you to read as you read the corresponding files.

Search.scm

First, we define a couple of global variables. Now, we define the key data structure used in the implementation, namely that of a search-node, which has the following components: The key function is SEARCH which accepts the following arguments: visited - a "visited list" implemented similarly to expanded. This can be #f. The SEARCH function is quite simple.
  1. If the pending list is empty, return indicating failure.
  2. Let current be the next element in pending. The implementation of the pending list will determine what node is next, for example, it could be the one with the least cost or simply the most recently added node.
  3. If we have an expanded list and the state of the current node is in the expanded list, then discard it and call search again.
  4. If the node's state is the goal, display the path and return the current node.
  5. Update the pending list by calling SEARCH-UPDATE with the successors of the current node and call search again.
The SEARCH-UPDATE function form updates the pending, expanded and visited lists. In its simplest form, it adds the current node to the expanded list (if present) and then filters out any nodes whose states are in the visited or expanded lists (if present) and adds them to the pending and to the visited list (if present). There is a much more elaborrate version of this function defined in SEARCH-UPDATE.SCM , we will look at that later.