资源描述:
《艾伯特Introduction to Prolog》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、troInductiontoPrologWhatisProlog?{Prolog(ProgramminginLogic)isaprogramminglanguageforAIandumericalnon-nprogrammingingeneral.Whatisnew?{tionalConven(wellestablished,standard)languagesareprocedurallyoriented,whilePrologintroducesthedeclarativeview.1.taxSynofProlo
2、g(a)clausesAPrologprogramconsistsofclauses.APrologclauseisaHornclause.Eachclauseterminateswithafullstop.Prologclausesareofthreetypes:rules,facts,andquestions.Example1:rule{ospring(X,Y):-parent(Y,X).Example2:fact{parent(tom,ann).Example3:questions{parent(X
3、,ann).(b)proceduresAgroupofclauseshwhictheheadofeachclausearethesameiscalledaprocedure.Example:connects(san_francisco,oakland,bart_tran).connects(san_francisco,fremont,bart_tran).connects(concord,daly_city,bart_tran).(c)rulesAruleisaclausewithoneormoreconditio
4、ns.orFaruletobetrue,allofitsconditionsmustalsobetrue.Theright-handsideoftheruleisaconditionandtheleft-handsideoftheruleistheconclusion.The`:-'signmeans`if'.TheclauseinExample1canbestatedasXisanospringofYifYisaparentofX.Theleft-handsideiscalledtheheadoftherule
5、andtheright-handsideiscalledthebodyoftherule.Thebodyofaruleisalistofgoalsseparatedbycommas.Commasareunderstoodasconjunctions.Example:p:-q,r,s,t.meanspistrueifqandrandsandtaretrue.(d)factsactsFarealwaysunconditionallytrue.Itonlyhasaheadpart(theconclusion)withan
6、emptybody.1www.aibbt.com让未来触手可及Example:has(student,books).(e)questionsQuestionsarequeriesforretrievingfactsthroughrules.Itonlyhasthebody(thegoals).Example:
y(penguin).(f)argumentsArgumentscanbeanatom,anumber,aariable,vorastructure.(g)atomsAtomsareconcreteobj
7、ects(butumbersnareNOTatoms).Therstletterofanatomisaysalwasmallletter.Stringsofletters:tom,nil,x25,x25AB,x,xy,toppartStringsofspecialcharacters:<
8、>,===>,...,.:.(withcaution)Quotedstrings:om','T'SouthAmerica'(h)numbersThesyntaxofintegersissimpleexceptonemustr
9、ememberthattherangeofintegersislimitedtoanal,tervininSICSTUSProlog,eenbetw-16383to16383.Examples:3.1416,-0.001,22.223,100(i)ariablesvariablesVaregeneralobjec