Chapter 3 Flashcards
Constants
Must start with a lower letter which can be followed by letters, underscores or digits.
It can also be a quoted string.
Quoted string
Any string of characters (other than single quote) enclosed within single quotes
Are these allowed constants in Prolog?
- George
- granny_sarah
- ‘Hello world’
- ’ _ ‘
- No
- Yes
- Yes
- Yes
Variables
Can start with uppercase and can be followed by any number of letters, underscores and digits
Atomic sentences (or atoms)
they have the following form:
predicate(argument1, …., argumentN)
where predicate = Prolog constant and
arguments = Prolog constants/variables
We always need parenthesis after the predicate unless it has 0 arguments
Think of two examples of correct Prolog atomic sentences in the KB.
- child(john, sue)
2. my_car(red, ‘bmw’)
Conditional sentences (clauses)
structure –> head :- body1, … , bodyN
head –> Prolog atom (then..)
body –> Prolog atom (if…)
Think of an example of a Prolog conditional sentence
sister(X, Y) :- female(X), person(Y), sibling(X, Y)
What would be a case where an atomic sentence is just a special case of a conditional sentence?
A case where a conditional sentence has an empty body (“if” part)
Example:
sister(X, Y) :- nothing –> in this case, sister(X, Y) is just a special case of a conditional sentence.
A Prolog program is a sequence of …
clauses
Prolog clauses can be …
atomic/conditional sentences
Where can spaces, newlines and comments be inserted in a Prolog program?
- at the end of a program or
2. just before a constant or a variable
Comments can be added followed by the character…
%
What is the goal of Prolog by answering a query?
To establish whether there is a relationship between the query and the KB
Query
Atom with/without variables terminated by a period.