constraints on PROLOG imcrprciaiłons. In Scction 14.7 mcta-prcdicatcs are uscd foj lwi Iding mćta-inurpirlcrs in PROLOG. Mcta-interprcters arc uscd lo build a PROLOG interpreter in PROLOG, as \vcll as to build interpretera for rulc chaining and inhcritaocc scarches.
In Scction 14.8 we dcmonstrate PROLOG as a languagc for machinę teaming, «id e\amples of vcrsion space search and cxp!anation-bascd Icarning from Chaptcr 9. In Sec* tion 14.9 we build a recursric desccnt semantic net parser. boscd on ideas dcwloped in Chaptcr 13. The chaptcr ends with the discussion of the generał issues of programminjin logie and procedura! ycisus dcclarativc problem solving.
Allhough thcrc are numerous dialccts of PROLOG, the syntax uscd throughout this tenis the original Warren and Pereira C-PROI.OG (Clocksin and Mcllish 1984). To simplify c* presentation of PROLOG, our vcrsion of predicate calculus syntax in Chaptcr 2 uscd many PROLOG coiwcntions. Thcrc arc, howcvcr. n number of dilfcrenccs bctwccn PROLOG and predicate calculus syntax. In C-PROLOG. for cxamplc, the symbolrcpbctt the t- of ftrst-ordcr predicate calculus. Othcr symbols differ from those uscd in Chaptcr 2:
ENGLISH |
PREDICATE CALCULUS |
PROLOG |
and |
A |
* |
or |
V |
"• w. |
onlyif |
& | |
not |
not |
As in Chaptcr 2. predicate names and bound variables are expresscd as a sequcncecf alphanumerie characters beginning with an alphabetic. Variablcs are represented as a string of alphanumerie characters beginning (at least) with an uppercasc alphabetic. Tb*
IStospe. susie).
tikes(Everyone. susie).
could represera the fact ihat “everyonc likes Susie.** Or. likesfgeorge. Y). likos(susio. Y).
could represent the set of things (or peoplc) that are likcd by both George and Susie.
Similarly, supposc it was dcsircd to rcprcsoni in PROLOG the folknyihg rclation-słaps: "Gcorge likcs Katc and Gcorge likes Susie.” Tliis could be stated as:
likes{george. kata), likes(georgo, susie).
Likewise. "Gcorge likes Kate or Gcorge likcs Susie":
likes(goorgo, kate): likes(george, susie).
Finally. “Gcorge likcs Susie if Gcorge docs not likc Kate”:
likos(georgo, susie)not(iikes(george, kate)).
Thesc cxamples show how the predicate calculus conncclwes a, v, and <- are cxprcs$ed in PROLOG. The predicate names (likes). the number or order of parameters, and evcn whether a given predicate always has the same number of parameters are deter-mincd by the design requircmcnts (the implicii "semanties") ofihc problem. Thcrc arc no cipre$sive limitations, other than the syntax of welhformcd formulae. in the language.
A PROLOG program is a set of specificalions in the first-order predicate calculus describing the objects and relations in a problem domain. The set of specificalions is referred to os the t/aiabase for that problem. The PROLOG interpreter responds to qucv lions about this set of spccifications. Qucries to the databasc are patteras in the same logi-cii syntax as the databasc entries. The PROLOG interpreter uses panern-directed search to ftnd whether these queries logically follow front the contents of the databue.
The interpreter processes ąucrics. scarching the databasc in left to right depth-fint order to find out whether the query is a logical conscqucnce of the databasc of spccitka-tkms. PROLOG is primariły an interpreted language. Socne \ er>ion> of PROLOG ran m ioterpretwe modę only. whilc others alkmr compilation of part orali of the set of spcdfica-tionS for faster cxccution. PROLOG is an inteiactive language; the user enters gueries in responsc to the PROLOG prompt: ?-.
Supposc that wc wish to dcscribc a “workT consisting of Gcorge s. Katc s. and Susic's likcs and dislikes. The databasc might contain the folkwing set of predicatcs:
Ukes(goorge, kate).
Hkos(goorge. susie), fikesfgeorge, winę).
Iik08(su8le, wino). llkos(kato, gin). liJces(koto, auslo).
Tte set of spccifications has the obvious imerpretanoo. or mapping. iaio the wońd of Gcorge and his friends. This world is a model for the databasc (Scctioo 2J). The mter-pKter may then bc asked qucstions:
?' likes(george. kate).
605