The Buggy Program

## 5.1 The Buggy Program

The program we will be debugging is a map colouring problem. The task is to colour a ‘map’ of countries with four colours such that no two neighbours have the same colour. Our program colours a map of four countries, but has a bug and can colour two neighbours the same colour. The map is displayed graphically as shown:

Map Display of Program

The countries are identified by numbers displayed within each country, and in this case, an incorrect colouring for the map is shown, because countries 3 and 4 have the same colour.

This program uses code from the map colouring demo program, and is designed to use the GUI to display a map. Most of this is not relevant to our debugging session, and although we will see some of this code during the debugging, it is not necessary to understand it. You can think of this debugging session as debugging someone else’s code, not all of which needs to be understood.

The program used here is included with your ECLiPSe distribution. You should find it under the doc/examples/tutorial directory. You can change to the examples directory in TkECLiPSe using the Change to example directory option from the File menu.

The final step in this debug tutorial is to edit the buggy program and correct it. If you want to do this, you should copy the distributed version of the program elsewhere so that you don’t edit the original. You need to copy the following files from `examples/tutorial` to another directory:

>     debugdemo.ecl  mapcolour.ecl mapdebugdemo.tcl buggy_data.map

To load the program, start TkECLiPSe. After start up, switch the working directory to where you have the programs – if you are using a UNIX system, and have started TkECLiPSe in the directory of the programs, you are already there. Otherwise, go to the File menu of TkECLiPSe, and select the Change directory option. Use the directory browser to find the directory containing your programs and select it. This will change your working directory to the selected directory.

Next, compile `debugdemo.ecl`. You can do this by selecting the Compile option from the File menu (you can also compile the file with the query `[debugdemo]` from the query entry window).