Information Technology Reference
In-Depth Information
Figure 3.2.
A run of Prolog with the family example
[linux]> swipl % Start SWI-Prolog.
Welcome to SWI-Prolog (Multi-threaded, Version 5.6.47)
Copyright (c) 1990-2007 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- [family]. % Load the family.pl file.
family compiled 0.00 sec, 2,728 bytes % The .pl part is not used.
Yes
% No errors were detected.
?- father(sam,jane).
% A first query to Prolog
Yes
% returns success.
?- father(jane,sam).
% A second query to Prolog
No
% returns failure.
?- halt.
% Exit SWI-Prolog.
[linux]>
3.2.1 Queries and their outcomes
In its simplest form, a Prolog query is just an atom (with or without variables) and
terminated with a period. Note that by entering an atom after a ?- the user asks Prolog
to establish the query, just as was done in chapter 2. This should not be confused with
adding the atom to the knowledge base. In other words, father(sam,jane) is not
telling Prolog that Sam is a father of Jane; it is asking if Sam is a father of Jane. (All
the telling took place when the family.pl file, containing the knowledge base, was
loaded using the square brackets.)
When Prolog is asked to establish a query with no variables, there are only three
possible outcomes:
Prolog answers Yes —this means that the atom can be established by back-
chaining as was the case with father(sam,jane) .
Prolog answers No —this means that the atom cannot be established by back-
chaining as was the case with father(jane,sam) .
Prolog does not answer—this means that the atom cannot yet be established but
that Prolog is continuing to try alternatives.
 
 
Search WWH ::




Custom Search