Directives start with the symbol ‘:-’. Any required output must be programmed explicitly; e.g. the directive:
:- memb(3, [1,2,3]), write(ok).
asks the system to check whether
3 belongs to the list
[1,2,3]. Execution of a directive terminates when all the
goals in the directive have been successfully executed.
Other alternative solutions are not sought. If no solution can be
found, the system prints:
* Goal - goal failed
as a warning.
The principal use for directives (as opposed to queries) is to allow files to contain directives that call various predicates, but for which you don’t want to have the answers printed out. In such cases you only want to call the predicates for their effect, i.e. you don’t want terminal interaction in the middle of consulting the file. A useful example would be the use of a directive in a file that consults a whole list of other files, e.g.:
:- consult([ bits, bobs, main, tests, data, junk ]).
If a directive like this were contained in the file myprog, typing the following at top-level would be a quick way of reading in your entire program:
| ?- [myprog].
When simply interacting with the top-level, this distinction between queries and directives is not normally very important. At top-level you should just type queries normally. In a file, queries are in fact treated as directives, i.e. if you wish to execute some goals, the directive in the file must be preceded by ‘:-’ or ‘?-’; otherwise, it would be treated as a clause.