Page 207 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 207

Unit 14: Prolog




          14.4 Prolog Terminology                                                               Notes

          Prolog’s single data type is the term. Terms are either atoms, numbers, variables or compound terms.

          14.4.1 Atom

          An atom is a general-purpose name with no inherent meaning. It is composed of a sequence of
          characters that is parsed by the Prolog reader as a single unit. Atoms are usually bare words in
          Prolog code, written with no special syntax. However, atoms containing spaces or certain other
          special characters must be surrounded by single quotes. Atoms beginning with a capital letter
          must also be quoted, to distinguish them from variables. The empty list, written [], is also an
          atom.

                 Example: Other examples of atoms include x, blue, Taco, and some atom.

          An atom is a data object in ProLog and is also used as a name of an individual or a predicate. An
          atom is a word-like entity and has the following characteristics:
              It begins with a lowercase letter and contains letters, digits, and an underscore.

              It can be enclosed in single quotes that contain any character, such as a space.
              It does not have a length limit.


                 Example: Some examples of atoms are:
          sam: An atom with only alphabet characters
          a_long_word: An atom with embedded underscores

          ‘New Jersey’: An atom enclosed in parentheses because it contains an embedded space
          13$$56: An atom starting with digits
          Use atoms to construct more complex entities, such as structures and lists

          14.4.2 Numbers

          Numbers can be floats or integers. Many Prolog implementations also provide  unbounded
          integers and rational numbers. All standard ProLog implementations have numbers that are
          positive,  negative, or floating-point integers. Some implementations  handle the exponential
          format.
          The knowledge base in ProLog is written in free format because there is no on the number of
          free spaces that a program can have. A new line is allowed at any point in the program but there
          are two restrictions: the atom or variable name cannot have embedded spaces and there cannot
          be anything between the function and the opening parentheses.

          Listing 1  shows a ProLog program that has a knowledge  base of facts and  rules related to
          hardware equipments:
          Listing 1: Identifying Hardware Equipment

          /* Program to identify hardware */
          /* Rule to check for hardware */
          hardware(X) :- equipment(X).




                                           LOVELY PROFESSIONAL UNIVERSITY                                   201
   202   203   204   205   206   207   208   209   210   211   212