Prolog Flashcards
B :- A
Implication, A -> B
,
And
;
Or
Atom
- A sequence of letters, digits or underscores that starts with a lowercase letter (car)
- A sequence of letters, digits or underscores that are enclosed in single quotes (‘car’)
- A string of special characters (:- or ,) (without the quotes, thus not a Python string format)
Number
Any sequence of numbers, possibly containing a dot
Variable
A sequence of letters, digits or underscores that starts with an upper case letter or an underscore (Car)
_ is the anonymous variable
A term is defined recursively:
- Each constant and variable is a term
- f(t1, …, tk) is a term is each ti is a term and f is an atom
— (this is a compound term with functor f and arity k indicated as has_wheels/1)
— a term is a ground when it contains no variables
Predicate
Any constant or compound term
Fact
A predicate immediately followed by a dot
Rule
A predicate is a rule if:
- given by A0 :- A1, …, An. With n>=0 and each Ai a predicate.
A0 is the head, A1, …, An is the body of the rule
Clause
Any fact or rule,
Are universal
Definition of a predicate
The set of all facts and rules that use a certain predicate P,
if there is no definition in a certain program, P is called undefined
Built in predicate
Defined by SWI Prolog (member/2)
Query
Defined as ?-p
Where p is some predicate known as a goal
Constant
Atoms and numbers