Department of Computer Science



next up previous
Next: Goals Up: A goal directed programming Previous: A goal directed programming


Programs, the Interpreter and an Example


Subsections

The following example is based on using the C-Prolog system on a BSD Unix system, but many Prolog interpreters have a similar interface. When the interpreter is started it immediately prompts for a goal:

      % prolog
      C-Prolog Version 1.4
      | ?-

Entering Programs

However a program consists of facts, rules and a goal. To enter a program either (a) put the facts and rules in a file and type the file name enclosed in brackets followed by a period .:

      | ?- [testprog].
       ........
      | ?-
or (b) give the file name ``user'' and enter the program directly:
      | ?- [user].
      supports(a,b).
      supports(a,c).
      supports(b,d).
      supports(c,e).
      ^d
      [eof] 
      | ?-
To terminate program entry and get the goal prompt type the end-of-file character (usually control and d). The above is hardly a program as it only contains simple asserted relationships (or facts) but it is only intended to demonstrate facts and goals.

The above facts are supposed to describe the state of a few blocks on a table:

\psfig{figure=blocks.eps}


next up previous
Next: Goals Up: A goal directed programming Previous: A goal directed programming


Page generated: 2002-11-04 by Bob Dickerson

© University of Hertfordshire Higher Education Corporation (1998)

Disclaimer