Upload
onawa
View
23
Download
0
Embed Size (px)
DESCRIPTION
Chapter Two: Syntax and Meaning of Prolog Programs. Chapter two:. 2.1 Data objects. 2.1 Data objects. 2.1.1 Constants: atoms String of letters, digits and the underscore character ‘_’ starting with a lower-case letter e.g. anna x25 x_34a x___y3 miss_Jones - PowerPoint PPT Presentation
Citation preview
1
Chapter Two: Syntax and Meaning of Prolog Programs
2
Chapter two:2.1 Data objects
data objects
simple objects
constants
atoms numbers
variable
structures
3
2.1 Data objects 2.1.1 Constants: atoms
String of letters, digits and the underscore character ‘_’ starting with a lower-case lettere.g. anna x25 x_34a x___y3 miss_Jones
String of special characterse.g. <----> ===> … ::= when using atoms of this form, be carefulbecause some of strings already havea predefined meaning e.g. ‘:-'
String of characters enclosed in single quotese.g. ‘Tom’ ‘tom’ ‘SarahJones’
The lexical scope of atom names is the whole program.
data objects
simple objects
constants
atoms numbers
variable
structures
4
2.1 Data objects 2.1.1 Constants: numbers
Prolog is a primarily a language for symbolic and non numerical computation.
In symbolic computations, integers are often used, e.g. to count the numbers of items in a list; but there is less need for real numbers. Integer numbers
e.g. 1 133 0 -97 Real numbers
e.g. 3.14 -0.0035 100.2
data objects
simple objects
constants
atoms numbers
variable
structures
5
2.1 Data objects 2.1.2 Variables
Variables are strings of letters, digits and underscores characters, starting with upper-case letter or an underscore.e.g. X Result Object2 _23 Shopping_list _ (the anonymous variable)
The lexical scope of variable names is oneclause except the anonymous variable; it signifies new variable each time itoccurs even in the same clause.e.g.
somebody_has_child:-parent(_,_).somebody_has_child:-parent(X,Y).somebody_has_child:-parent(X,X).
data objects
simple objects
constants
atoms numbers
variable
structures
6
2.1 Data objects 2.1.3 Structures
Structures are objects that have several components which can be structures themselves.e.g. date (1, may, 2001)
to represent any day in may; day is variable date (Day, may, 2001)
All structures can be pictured as tree.
Each functor is defined by name and arity (#of arguments)
functor arguments (all are constants)
date
may1 2001
data objects
simple objects
constants
atoms numbers
variable
structures
7
2.1 Data objects 2.1.3 Structures
Example: how structures can be used to represent the following geometric objects: A point in 2 dimensional space A line segment A triangle (a + b) * (c - 5)Draw the tree structures thatcorrespond to them.
data objects
simple objects
constants
atoms numbers
variable
structures