CS 342 Lecture -*- Outline -*- * Pure Prolog ** Structure *** program is list of horn clauses (b if c, d, e; written b :- c,d,e) variables are universally quantified, may be substituted by wffs predicates cannot be quantified ** Claims of Prolog significant advantage over LISP small program modules (clauses), little nesting DEC-10 prolog more efficient than comparable LISP! ease of programming clear, readable, concise programs reduces errors and development costs ** C-Prolog syntax describes facts and relationships ------------- ::= * % or of clauses ::= :- { , }* . % rule . % assertion ?- { , }* . %** cf. book % goal, question ::= | | ( ) ::= ::= _[A-Za-z0-9_]* | [A-Z][A-Za-z0-9_]* ::= | ::= [a-z][A-Za-z0-9_]* | ::= 'chars' comment convention is % rest of line or /* comment */ ------------- *** Examples: **** compound terms: functor + arguments (functor like a noun) tree(Subtree1,Root,Subtree2) lists: [a,b], which is sugar for .(a, .(b, [])) sentence(np(n(ron)), vp(v(gave),np(art(a), n(paper)), compls(prep(to), np(n(sue))))) **** general clause: get_A(X) :- gotAonExams(X), gotAonHWs(X), understoodProlog(X). scope of X is just this clause! **** assetions ------------- % a semantic network object(event1, paper). recipeint(event1, sue). actor(event1, ron). action(event1, gave). ------------- **** queries: ?- object(event1,paper). %(was the object of event1 a paper?) yes ?- object(event1,What). %(what was given in event1?) What = paper ?- actor(Event,Who), action(Event, gave). %(who gave in an what event?) Event = event1 Who = ron; no % no more ways to satisfy goal ?- actor(X,Y), action(X,Z). X = event1 Y = ron Z = gave ** Interpretations of clauses e.g., h(X) :- b1(Y), b2(Z), b3(W). *** declarative to solve problem of form h, need to solve {b1,b2,b3}. logic (an implication): b1(Y) and b2(Z) and b3(W) imply h(X) i.e: h(X) if b1(Y) & b2(Z) & b3(W). Knowledge based systems rule (if-then rule), with antecedents bi() and consequent h(X). *** Procedural reading (programming language) procedure with head h(X), body b1(Y), ... head h identifies form of call it can answer, body {b1,b2,b3} is an ordered list of procedure calls.