[Next] [Up] [Previous]
Next: About this document Up: Stored Knowledge Previous: Reviewing the answer Procedure

Exercises

  1. The classic example used to demonstrate scripts involves eating in a restaurant. Try and write out a script describing both the typical events in a waiter-service restaurant and also unusual occurrences, such as the actions taken if the food arrives burnt.
  2. Write your own version of the Tourist Guide's database, in a form similar to the one shown on page [*]. Base it on some town or region you like visiting. Write a version of the answer procedure to handle five different types of question that might be asked by a tourist visiting your chosen area.
  3. Suppose that the search pattern at stage 3 on page [*] had been, not
    [^x underground ?y] but [^^x underground ??y], and with variable x having the value [the national gallery]. What would the relevant database entry need to look like in order for the search pattern to match it, in such a way that the variable y would be assigned the value [trafalgar square]? Why?
  4. Given that the variables x and y have values as in exercise 3, what list would be printed out if the response pattern had been

    [the nearest underground station to ^x is ^y]

    Explain why the use of double up-arrows is preferable.

  5. Define a procedure, addlist, along the lines of add given on page [*], which adds each new item to the end of the database. Incorporate this in a procedure that will keep a diary consisting of an entry for each day, such as

    [mon june 29 - went fishing]
    [tue june 30 - visited planetarium]

    and so on.

  6. Here is a definition for a procedure excise, which works rather like the built-in procedure remove.

        define excise(item);
    
            vars x y;
    
            if database matches [??x ^item ??y] then
    
                [^^x ^^y] -> database;
    
                [^item has been removed] =>
    
            else
    
                [sorry - ^item is not there] =>
    
            endif;
    
        enddefine;

    Imagine that your diary database (see the previous question) erroneously contains an entry for the nonexistent date: wed june 31. Show how the procedure excise might be used with a suitable list pattern to delete that particular entry. Using excise as a model, write a procedure replace, with two arguments, which finds a given entry in the database and replaces it with a new item.

  7. Construct a database describing an imaginary world of toy blocks or other objects sitting on a table, like that given in the MSBLOCKS example. Limit the scene to about ten objects. Write a version of answer which can reply to simple questions about objects on the table, and maybe change the database if actions like ``Pick up the red block'' are requested. Write a brief description of the problems you encountered in this exercise.

[Next] [Up] [Previous]
Next: About this document Up: Stored Knowledge Previous: Reviewing the answer Procedure

Cogsweb Project: luisgh@cogs.susx.ac.uk