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!
=== Predicates and programs === A ''predicate'' (or ''procedure definition'') is a collection of clauses whose heads have the same name and arity. We use the notation ''name/arity'' to refer to predicates. A ''logic program'' is a set of predicates. For example, the following Prolog program, which defines some family relations, has four predicates: <syntaxhighlight lang="prolog"> mother_child(trude, sally). father_child(tom, sally). father_child(tom, erica). father_child(mike, tom). sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y), not(X = Y). parent_child(X, Y) :- father_child(X, Y). parent_child(X, Y) :- mother_child(X, Y). </syntaxhighlight> Predicate <code>father_child/2</code> has three clauses, all of which are facts, and predicate <code>parent_child/2</code> has two clauses, both are rules. Due to the relational nature of many built-in predicates, they can typically be used in several directions. For example, <code>length/2</code> can be used to determine the length of a list (<code>length(List, L)</code>, given a list <code>List</code>), and to generate a list skeleton of a given length (<code>length(X, 5)</code>), and to generate both list skeletons and their lengths together (<code>length(X, L)</code>). Similarly, <code>append/3</code> can be used both to append two lists (<code>append(ListA, ListB, X)</code> given lists <code>ListA</code> and <code>ListB</code>), and to split a given list into parts (<code>append(X, Y, List)</code>, given a list <code>List</code>). For this reason, a comparatively small set of library predicates suffices for many Prolog programs. As a general purpose language, Prolog also provides various built-in predicates to perform routine activities like [[input/output]], using graphics and otherwise communicating with the operating system. These predicates are not given a relational meaning and are only useful for the side-effects they exhibit on the system. For example, the predicate <code>write/1</code> displays a term on the screen.
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)