next up previous contents
Next: Exercises Up: CHAPTER.1: INTRODUCTION --- Previous: Searching for information

Finding several rooms

If we wanted to dig out information about not just one room, but about several, then we could define a procedure to take a list of the names of wanted rooms, as well as the master list, and search for each required room in turn, using find_and_show:

    define find_and_show_all(namelist, list_of_lists);
        lvars name;
        for name in namelist do
            find_and_show(name, list_of_lists)
        endfor
    enddefine;
We can test it, by giving it a list of two room names and our global list_of_lists:

    find_and_show_all([room2 room4], rooms);
which prints out:

    INFORMATION CONCERNING: room2
      perimeter is: 54
      area is: 176
      volume is: 1408
    INFORMATION CONCERNING: room4
      perimeter is: 38
      area is: 90
      volume is: 810
You may already be able to see that we can define procedures which are much more flexible than this. In this example we always dig out the same sort of information, even though it may be about different rooms. We could define procedures which produce different sorts of information. E.g. given a width, find all the rooms with that width, or find all the rooms which have a given length and height, etc.

Later we shall see that use of the Pop-11 matcher would make this sort of flexibility much easier to achieve.



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