1 / 7

Chapter Two: Syntax and Meaning of Prolog Programs

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

onawa
Download Presentation

Chapter Two: Syntax and Meaning of Prolog Programs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter Two: Syntax and Meaning of Prolog Programs

  2. Chapter two: 2.1 Data objects

  3. 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 • String of special characters e.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.

  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

  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).

  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 variabledate (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 1 may 2001

  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 that correspond to them.

More Related