Validating Links in Web Pages - Tasks

Exercise tasks

You should attempt as many as you can of the following tasks. Remember, you must write each function to comply with the specification above, as well as with the instructions given below.

  1. MERGE-URLPATH

    Write MERGE-URLPATH. Use the following algorithm to merge the directories:

    If the directory is relative, then
    strip off the :RELATIVE flag and then append to the provided default.
    else
    it is absolute, return it.

    Notes: the function is not allowed to modify its arguments destructively. However, the value it returns may share structure with its arguments. You do not need to check that the given default argument is an :ABSOLUTE directory (though you can if you wish).

  2. INDEXIFY-URLPATH

    Write INDEXIFY-URLPATH. The function should destructively modify its argument.

  3. ELIMINATE-BACKS

    The two parts of this question will receive equal weight when marked.

    1. Write ELIMINATE-BACKS. Your object is to eliminate all pairs of DIRNAME :BACK from the argument dirlist. To do this, prune the list using the following algorithm:

      if the list is empty, then
      return the empty list
      else
      if the second element is :BACK, then
      if the first element is not :BACK, then
      return the result of pruning DIRLIST from the third element onwards
      else
      return a list: the first element should be :BACK, the second element should be :BACK, and the rest of the returned list should be the result of pruning the argument DIRLIST from the third element onwards
      else
      return a list: the first element should be the first element of DIRLIST, and the rest of the list should be the result of pruning the rest of the argument DIRLIST
      Check the result against the original DIRLIST. If it has not changed, then
      return the result
      else
      prune the result recursively by calling ELIMINATE-BACKS on the result

      Note: this may not destructively modify its argument. However its return value may share structure with the argument if that is convenient.

    2. Why is it necessary to compare the result of pruning with the argument list, and prune again? The algorithm given is inefficient, because it traverses the argument over and over again until there are no more pairs of DIRNAME :BACK which can be eliminated.

      Comment out your original version of ELIMINATE-BACKS. Write another version which uses a more efficient algorithm to eliminate all pairs of DIRNAME :BACK from the dirlist.

  4. PRUNE-DIRECTORY

    Write PRUNE-DIRECTORY. Use ELIMINATE-BACKS to remove any pairs of DIRNAME :BACK from the specification. Then if the path is absolute, strip off any leading chain of :BACKs from the front of the directory list.

    Note: this may not destructively modify its argument. However the return value may share structure with its argument if that is convenient.

  5. PRUNE-URLPATH

    Write PRUNE-URLPATH. This function must destructively modify its argument.

  6. CANONICALIZE-LINK

    Write CANONICALIZE-LINK. Call INDEXIFY-URLPATH, MERGE-URLPATH and PRUNE-URLPATH as necessary. This function will destructively modify its argument as it calls destructive functions.

  7. STORE-ALL-PAGE-DESCRIPTIONS

    Write STORE-ALL-PAGE-DESCRIPTIONS. This function must destructively modify its tree argument.

  8. URLPATH-VALUE-IN-UPT

    Write URLPATH-VALUE-IN-UPT. Note that the specification states that in certain circumstances an error or a warning should be signalled by URLPATH-VALUE-IN-UPT. Use ERROR and WARN to signal these in your version.

  9. MAP-UPT-NODES

    Write MAP-UPT-NODES. Hint: You may wish to implement this by defining an auxiliary function with an additional parameter. Note that the argument fn should be called with two arguments; the name of the node and the node itself. This is analogous to the behaviour of MAPHASH. Note also that the name of the given root node is "".

  10. URLPATH-DANGLING-LINKS

    Write URLPATH-DANGLING-LINKS. Follow the specification carefully.

  11. UPT-DANGLING-LINKS

    Write UPT-DANGLING-LINKS.

  12. UPT-DANGLING-PATH-NAMES

    Write UPT-DANGLING-PATH-NAMES. This function will return the names of all the dangling links in a form in which, if printed, you can easily read them on the screen (compare its result to the result of UPT-DANGLING-LINKS).

Authors: Gail Anderson (ga@cley.com), Tim Bradshaw(tfb@cley.com), Cley Limited.
Copyright 1999–2003 Cley Ltd. & Franz Inc.