Getting Started
February 17, 2019 ยท View on GitHub
Start D-Prolog
$ dprolog
?-
With an initialization file:
$ dprolog -f example/family.pro
?-
?- male(X).
X = bob;
X = tom;
X = jim.
Stop D-Prolog
?- halt.
or input ctrl+c or ctrl+d to stop D-Prolog.
Options
-h,--help: Print a help message-v,--version: Print version of dprolog-f,--file=VALUE: ReadVALUEas an initialization file--verbose: Print diagnostic output
Example Prolog files
example/family.proexample/list.proexample/factorial.proexample/if.pro
Load a file while running
Input a query ?- [<file path>]. while running as follows:
?- [`file.pro`].
?- [`/path/to/file.pro`].
Add rules from the console
Input a query ?- [user]., and you will be able to add rules from the console:
?- [user].
|: hoge(poyo).
|:
Input ctrl+c or ctrl+d to exit from the mode for adding rules.
?- hoge(X).
X = poyo.
Comments
The %-style line comments are supported.
?- X = 1. % This is a comment.
X = 1.
Lists
?- X = [a, b, c].
X = [a, b, c].
?- X = [a | [b, c]].
X = [a, b, c].
Integers and Arithmetic Operations
?- X = 10. % A decimal literal
X = 10.
?- X = 0b1010. % A binary literal
X = 10.
?- X = 0xff. % A hexadecimal literal
X = 255.
?- X is 1 + 2.
X = 3.
?- X = 10, Y is X * X - 1.
X = 10, Y = 99.
?- 10 < 100.
true.
Conjunctions and Disjunctions
$ dprolog -f list.pro
Conjunctions:
?- member(X, [1, 2, 3]), member(X, [3, 4]).
X = 3;
false.
Disjunctions:
?- member(X, [1, 2, 3]); member(X, [3, 4]).
X = 1;
X = 2;
X = 3;
X = 3;
X = 4;
false.
Conjuctions and disjunctions:
?- member(X, [1, 2, 3]); member(X, [3, 4]), X > 3.
X = 1;
X = 2;
X = 3;
X = 4.
?- (member(X, [1, 2, 3]); member(X, [3, 4])), X > 3.
X = 4.
Cut Operator
?- X = 1; X = 2.
X = 1;
X = 2.
?- X = 1, !; X = 2.
X = 1.
Load example/if.pro, then
?- if(true, X = 1, X = 2).
X = 1.
?- if(false, X = 1, X = 2).
X = 2.
If you want to know more about D-Prolog, see Specification.