next up previous contents
Next: Searching for information Up: CHAPTER.1: INTRODUCTION --- Previous: "Top down" and

Exercise on the ROOMS example

The rooms example illustrates features of Pop-11 which need to be explained in more detail later on. The following exercise should test your understanding so far.

1. Modify the program so that in addition to the information shown above, the dimensions of each room are printed out, before the perimeter. You will need to work out which procedure should be modified, and how to modify it. All the techniques required have already been demonstrated.

Some further questions for revision:

2. Explain what the `for....endfor' form achieves.

3. What is a local variable? What is the difference between an input local and an output local? How are additional local variables declared? (More on this in later chapters.)

4. In the left half of the imperative:

        area(len, breadth) * height -> total;
there are five expressions denoting numbers. What are they? Hint: here are two of them:

    breadth, area(len, breadth),
Explain the difference between `->' in a procedure heading and in an assignment instruction. One of them causes a value to be copied from the Pop-11 stack to a variable. The other specifies that a value should be left on the stack when a procedure finishes. Which is which?

6. What are lexical rules for? How many separate items would the Pop-11 lexical rules find in the following line:

    [room3 44hat 999+x ]
Hint: you can find out by printing it out thus:

        [room3 44hat 999+x ] =>
or using listlength, to count the items, thus:

        listlength([room3 44hat 999+x ]) =>
Suppose you wanted to be able to answer questions about which rooms were connected to which, and questions about which rooms you had to pass through to get from e.g. room1 to room4. (This could be essential information for an adventure-game program, or a route-planning program). How might you enrich the ontology of the problem? E.g. what additional objects, properties and relationships might be involved? How would you represent the additional information in the the "rooms database", i.e. the list of lists of information about rooms? (There are several different ways of doing this. Try to invent one.)

A possible answer: suppose that the rooms are all rectangular and aligned with the compass points. Then a room that is connected to room5 via its eastern wall could have the following information added to its list:

    [east room5]
Try drawing a plan of a house, including a corridor and some rooms, and then see how you can represent the rooms, the corridor, and their connectivity. What about the external doors? Would the above representation of dimensions as length, breadth and height adequately show the configuration of each room, or which a different representation be better?



next up previous contents
Next: Searching for information Up: CHAPTER.1: INTRODUCTION --- Previous: "Top down" and



Aaron Sloman
Fri Jan 2 03:17:44 GMT 1998