Programming in Prolog by William F. Clocksin, Christopher S. Mellish

george_smith ieh2304 The following are not examples of atoms: 2304ieh george-smith Void _alpha Integers, the other kind of constant, are used to represent numbers, so that arithmetic operations can be carried out.

The following goal a(b,C,d(e,F,g(h,i,J») • a(B,c,d(E,f,g(H,i,j») would succeed, and cause B to be instantiated to b, C to c, E to e, F to f, B to h, and J to j. What happens when we attempt to make two uninstantiated variables equal? This is just a special case of the first rule above. The goal succeeds, and the two variables sbare. If two variables share, then whenever one of them becomes instantiated to some term, the other one automatically is instantiated to the same term. So, in the following rule, the second argument will be instantiated to whatever the first argument is: do-nothing(X,Y) :- X-Yo An X = Y goal will always succeed if either argument is uninstantiated.

A[]), and its tree looks like this: a / \ [] Also, the list consisting of the atoms a, b, and c could be written . (a •. (b •. (c • []»), depicted as: a / \ / \ b c / \ [] The dot functor happens to be defined as an operator, so it is permissible to write the above two lists as a. (c. []»). The second one could be written simply as a. b. c. [], because dot is right associative. Lists are an ordered sequence, so the list a. b is different from the list b. a. Some people like to write the tree diagram of a list with the tree "growing" from left to right, and with the "branches" hanging down.

Download PDF sample

Rated 4.97 of 5 – based on 34 votes