Module 6

Output and program design

Objectives

This module gives an example of output in Prolog. This example is part of a program that is later used to demonstrate program design in Prolog.

Some output predicates

Prolog has several predicates that are used to produce reasonably well structured output fairly easily. The most commonly used are described in this section, together with examples of centring text of differing lengths.

Program design

It is not enough to have an informal statement of what a program should do and to hope that this can be converted effortlessly straight into program code. This section shows how problems can be successively divided (or "refined") into parts which result in the production of the code to be used in the program. This section uses the example of filling a "magic square" with the numbers from one to nine, such that each row, column and diagonal sums to fifteen. The final program represents a very naive way of finding a solution, in that it relies on looking at each alternative way of filling the board until a correct one is found.

--------------------------------------------------------------------------

Navigation Menu

--------------------------------------------------------------------------

These Pages are maintained by Dr Peter Hancox

Last updated October 1998