Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Prolog
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Rules and facts === Prolog programs describe relations, defined by means of clauses. Pure Prolog is restricted to [[Horn clause]]s. Two types of Horn clauses are used to define Prolog programs: rules and facts. A rule is of the form <syntaxhighlight lang="prolog">Head :- Body.</syntaxhighlight> and is read as "Head is true if Body is true". A rule's body consists of calls to predicates, which are called the rule's '''goals'''. The built-in [[logical operator]] <code>,/2</code> (meaning an arity 2 [[Operator (programming)|operator]] with name <code>,</code>) denotes [[logical conjunction|conjunction]] of goals, and <code>;/2</code> denotes [[logical disjunction|disjunction]]. Conjunctions and disjunctions can only appear in the body, not in the head of a rule. Clauses with empty bodies are called '''facts'''. An example of a fact is: <syntaxhighlight lang="prolog">human(socrates).</syntaxhighlight> which is equivalent to the rule: <syntaxhighlight lang="prolog">human(socrates) :- true.</syntaxhighlight> The built-in predicate <code>true/0</code> is always true. Given the above fact, one can ask: ''is socrates a human?'' <syntaxhighlight lang="prolog"> ?- human(socrates). Yes </syntaxhighlight> ''what things are humans?'' <syntaxhighlight lang="prolog"> ?- human(X). X = socrates </syntaxhighlight> Clauses with bodies are called '''rules'''. An example of a rule is: <syntaxhighlight lang="prolog">mortal(X) :- human(X).</syntaxhighlight> If we add that rule and ask ''what things are mortals?'' <syntaxhighlight lang="prolog"> ?- mortal(X). X = socrates </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)