JOYTemplate for Letters group d2kIz k phlI Y%z kZ-KiZ-K N"զI` {x R< N"զI` {x R<L$ЦIz yx UL$ЦIz xx UL$ЦIz x UL$ЦIz ~x UL$ЦIz }x UL$ЦIz |x UL$ЦIz sx UL$ЦIz rx UStandard ++Y"zٺۻ[X۩zתڪRj}[Y{"wDdzwzz̼ݩywںۻxp陘ۚyۨ xScript 1: 0x R< PPROLOG:@AN`INTRODUCTIONDavidHarvey.Traditionalprogrammingislargelyconcernedwithspecifyingasequenceofactionstobeperformedbyacomputer'sprocessorovertheyears,thishasevolvedfromenteringmachineinstructionsbysettingswitchesonacontrolpanel,throughassemblers,tomodernprogramminglanguagessuchasBASIC,Pascal,andC.Whiletherearemarkeddifferencesbetween<these,thesurpisingthingistheamounttheysharetheconceptofvariablesandconstants,datattypes,flowofexecution(firstdothis,(thenthis,then...),controlstructures(if,while,for,etc),andsoon.Butimagineaprogramminglanguagewithnocontrolstructuresandno(instructions,inwhichaprogramnolongerspecifiestheactiontobeperformedbutmerelystatesfactsandrules ,andasksquestions. Prolog(itstandsforPROgramminginLOGic)issuchalanguage.AndifPitsoundsunusual,restrictiveeven,considerthatitwaschosenbyscienceandindustryinJapanasacornerstoneoftheirambitousx5th-generationcomputingproject.Generallythepreserveoflargecomputers,arestrictedformofthelanguagehasbeenavailableforsome(timeasMICROPROLOG.However,PROLOG80,availablethroughAdvantageforAmstradCP/Mmachines,isaremarkablycompleteimplemetationofthelanguage,conformingcloselytothestandard'Edinburgh'dialect(EdinburgUniversityisoneoftheprincipalcentresofdevelopmentofthePROLOGlanguage).APROLOGprogramestablishesasetoffactsandrules(generallyknownasthedatabase)whichcanthenbeinterrogated.AsimplePROLOGPdatabasemaytakethefollowingform(thisisastandard"Beginning8PROLOG"example!): likes(john,jane). likes(john,fred). likes(bill,fred). likes(fred,laetitia).PEachfactexpressesarelationshipinthiscaselikesbetweena xScript 1: 0x R< xnumberofobjectshere,people.(Jargonfortherelationshipispredicate,theobjectsbeingthearguments.)APROLOGsystemis(interactivethesimplestformofquestion(typesattheinteractive,prompt?)isafact,whichthesystemwilltrytoprove: ?likes(bill,jane).( No ?likes(john,jane). YesThesystem'sfirstresponse(No)signifiesthatthereisnobasisinthedatabasefortheclaim"billlikesjane",thesecond(Yes)thatitcanprovethat"johnlikesjane".Sofar,thesequestionshavesimplyasked xScript 1: 0x R< forconfirmationoffacts.Whenvariablesareintroduced,thelanguage'sppowerbecomesmoreapparent: ?likes(bill,X). X=fred( NoPROLOGdistinguishesbetweenitsownobjects,whichhavenamesbeginning<withalowercaseletter,andvariables,whichmustcommencewithanduppercaseletter.Whenaskedaquestioninvolvingavariable,thesystemattemptstomatchthevariabletoanobjectusingthefactsandrulesatitsdisposal.Thequestionabove(translatedas"doesbilllikeanyone?")producestheresponse"fred",then"No"tosignifythattheredisnooneelsewhombilllikes.Thefollowingquestionillustrateslanotherpowerfulfeatureofthelanguage: ?likes(john,X).4 X=jane X=fred( No(AfterfindingamatchforX(jane),thesystemattemptstoresatisfy<thegoalofitsquerywiththeremainingfactsatitsdisposal.Thisfeatureiscalledbacktracking.Goals(questions)mayinvolvemorethanonecondition: ?likes(john,X),likes(bill,X). X=fred( NoHere,thecompoundgoalissatisfiedbyonlyonevalueofX.<IfaPROLOGsystemweretocontainonlyfacts,itmaybeusefulasadflexibledatamanagementsystem,butlittleelse.Theuseofrules(allowsPROLOGtoinferfactsfromotherfacts.Aruleisspecifiedasfollows: likes(nellie,X):  hlikes(X,fred).Thistranslatesas"nellielikesXifXlikesfred",ormore(colloquially,"nellielikesanyonewholikesfred".Thefirstpartoftherulesucceeds(PROLOGjargonfor"istrue")onlyifallthestatementsinthesecondpart,orbody,succed.Giventhisrule: ?likes(nellie,X). X=john X=fred( NoPThebodiesofrulescanbeconsiderablymorecomplexthanthis,for xScript 1: 0x R< Pexamplethefollowingcouldbearuleinahypotheticalfamilytreedatabase: xScript 1: 0x R< L sister(X,Y):8  hfemale(X),  hparents(X,Ma,Pa),  hparents(Y,Ma,Pa),`  hX\==Y.dThismeans"XissistertoYifXisfemale,XandYhavethesameparents,andXisnotthesameasY".(AnyPROLOGsystemcontainsalargenumberofbuiltinpredicates,andPROLOG80isnoexception.Bynowdocumentationshouldbeavailableondiskdescribingeachofthese(theearlycopyIreceivedwasaccompaniedonlybyasampleprograminPolish!).Initiallythemostusefulofthese(areconsult(filename),whichwillreadinanASCIItextfileoffactsandrules,listing('',filename)towriteallcurrentfactsandrulestoanamedfile,andedit,whichallowsinteractiveeditingofthecurrentdatabase.Some(English!)examplesshouldhavefoundtheirwayontothedisktoo,alongwithsomeusefulpredicatesforlistandscreenhandling,aswellasacopyofthisarticle.Inashortarticle,there<isnowherenearenoughspacetodescribethepowerofthisimportant<language.Butifthishasinterestedorintriguedyou,PROLOG80hasmadeitpossibletoexperimentwithalanguageofthefuture.Forfurtherreading:ThestandardtextonPROLOGistheClocksinandMellishbookProgramminginProlog,publishedbySpringerVerlag.Thisisanexpensivepaperback,(butshouldbeavailableinlargerlibraries.TheAugust1987issueofPthejournalBYTEcontainsanumberofarticlesonthelanguage,and<thereisaseriesof4tutorialarticlesinPersonalComputerWorld,FebruaryMay1987.