My platform is Windows. After the installation of SWI-Prolog, add the SWI-Prolog bin directory to PATH environment varialbe. In my case, the bin directory is C:\Program Files\pl\bin.
SWI-Prolog has a plwin.exe which is GUI environment for SWI-Prolog. I prefer to use the SWI-Prolog console environment which is plcon.
- Open a command line
- change to directory containing my prolog source code. In my case, it is D:\documents\Prolog.
- type plcon to launch prolog
Now the command console looks as follows.
D:\Documents\Prolog>plcon
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.6.64)
Copyright (c) 1990-2008 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).
1 ?- consult(woman).
% woman compiled 0.00 sec, 1,060 bytes
true.
2 ?-
Type consult(women) to load D:\documents\Prolog\women.pro. It contains the following clauses.
:-dynamic pregnant/.
human(susan).
human(jane).
pregnant(susan).
woman(X) :- pregnant(X), human(X).
Assert can only be used to add facts to dynamic predicates in the prolog interpreter. I want to add facts for predicate pregnant. So I add the dynamic directive in the prolog source code. pregnant/1 is a predicator indicator. A predicate indicator is used to denote predicates. It's form is Name/Arity where Name is an atom denoting the name of a predicate and Arity is a integer denoting the number of its arguments. Add one fact to the prolog clause databse.
2 ?- assert(pregnant(jane)).
true.
Issue a query. Type ; to ask for more answers.
3 ?- woman(X).
X = susan ;
X = jane.
Type halt. to exit SWI-Prolog
4 ?- halt.
No comments:
Post a Comment