JOYTemplate for Letters group èÿÿà�dà�2–¶k…òI”z ¶kÐ pÐhlÂìŠI” Y÷%Á³Ðz ¶kZ-–K¥Òi´Z-–K¥ Nä"Õ¦I…` ¶{x R< Nä"Õ¦I…` ¶{x R<Lï$ЦI”z ¶yx ULï$ЦI”z ¶xx ULï$ЦI”z ¶x ULï$ЦI”z ¶~x ULï$ЦI”z ¶}x ULï$ЦI”z ¶|x ULï$ЦI”z ¶sx ULï$ЦI”z ¶rx UStandard €+¶¹+Yº²‚»»»»»"»›¹™©¹z¨Ùº¹ª«Û»[XÛ©šª¹z–תª©¹Úª™R¹»j–’¹‰ˆ¹™Ë}×[Y™°«ª{»»»»»ÝÝÝÝÝ"wD“dºzºwª§«zºzªšÌ¼«««¹›‰Ý©ºª«y™w»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»›¸ºº§Úº™¹»Û»©ˆ‰x©š¨¹™™»˜p陘œ�ªÛš»»º½­¹y‰¨¹¨™›™ªªÛ¨ˆš€€ xScript 1: 0x R< ÈP˜PROLOG:@AN`INTRODUCTION œDavidHarvey. Traditionalprogrammingislargelyconcernedwithspecifyingasequenceofactionstobeperformedbyacomputer'sprocessorovertheyears,thishasevolvedfromenteringmachineinstructionsbysettingswitchesonacontrolpanel,throughassemblers,tomodernprogramminglanguagessuchasBASIC,Pascal,andC.Whiletherearemarkeddifferencesbetween<these,thesurpisingthingistheamounttheysharetheconceptofvariablesandconstants,datattypes,flowofexecution(firstdothis,(thenthis,then...),controlstructures(if,while,for,etc),andsoon.Butimagineaprogramminglanguagewithnocontrolstructuresandno(instructions,inwhichaprogramnolongerspecifiestheactiontobe performedbutmerelystatesfactsandrules ,andasksquestions.  Prolog(itstandsforPROgramminginLOGic)issuchalanguage.AndifPitsoundsunusual,restrictiveeven,considerthatitwaschosenbyŒscienceandindustryinJapanasacornerstoneoftheirambitousx5th-generationcomputingproject.Generallythepreserveoflargecomputers,arestrictedformofthelanguagehasbeenavailableforsome(timeasMICROPROLOG.However,PROLOG80,availablethroughAdvantageforAmstradCP/Mmachines,isaremarkablycompleteimplemetationoftheŒlanguage,conformingcloselytothestandard'Edinburgh'dialect(EdinburgUniversityisoneoftheprincipalcentresofdevelopmentofüthePROLOGlanguage). APROLOGprogramestablishesasetoffactsandrules(generallyknownŒasthedatabase)whichcanthenbeinterrogated.AsimplePROLOGPdatabasemaytakethefollowingform(thisisastandard"Beginning8PROLOG"example!): ü likes(john,jane).ü likes(john,fred).ü likes(bill,fred).¬ likes(fred,laetitia). PEachfactexpressesarelationshipinthiscaselikesbetweenaÀ€ xScript 1: 0x R< Èxnumberofobjectshere,people.(Jargonfortherelationshipis predicate,theobjectsbeingthearguments.)APROLOGsystemis(interactivethesimplestformofquestion(typesattheinteractive,prompt?)isafact,whichthesystemwilltrytoprove: À ?likes(bill,jane).( NoÀ ?likes(john,jane). Yes Thesystem'sfirstresponse(No)signifiesthatthereisnobasisinthedatabasefortheclaim"billlikesjane",thesecond(Yes)thatitcanprovethat"johnlikesjane".Sofar,thesequestionshavesimplyasked€Ø€€ xScript 1: 0x R< Èforconfirmationoffacts.Whenvariablesareintroduced,thelanguage'sppowerbecomesmoreapparent: ü ?likes(bill,X).Ð X=fred( No PROLOGdistinguishesbetweenitsownobjects,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)mayinvolvemorethanˆonecondition: Ð ?likes(john,X),likes(bill,X).° X=fred( No ðHere,thecompoundgoalissatisfiedbyonlyonevalueofX. <IfaPROLOGsystemweretocontainonlyfacts,itmaybeusefulasadflexibledatamanagementsystem,butlittleelse.Theuseofrules(allowsPROLOGtoinferfactsfromotherfacts.Aruleisspecifiedasfollows: ü likes(nellie,X):è  hlikes(X,fred). ÜThistranslatesas"nellielikesXifXlikesfred",ormore(colloquially,"nellielikesanyonewholikesfred".Thefirstpartof therulesucceeds(PROLOGjargonfor"istrue")onlyifallthe statementsinthesecondpart,orbody,succed.Giventhisrule: Ô ?likes(nellie,X).° X=john° X=fred( No PThebodiesofrulescanbeconsiderablymorecomplexthanthis,forè€ xScript 1: 0x R< ÈPexamplethefollowingcouldbearuleinahypotheticalfamilytreeìdatabase:�Ø€ xScript 1: 0x R< È L sister(X,Y):8  hfemale(X),¬  hparents(X,Ma,Pa),¬  hparents(Y,Ma,Pa),`  hX\==Y. dThismeans"XissistertoYifXisfemale,XandYhavethesame¼parents,andXisnotthesameasY". (AnyPROLOGsystemcontainsalargenumberofbuiltinpredicates,andPROLOG80isnoexception.Bynowdocumentationshouldbeavailableondiskdescribingeachofthese(theearlycopyIreceivedwasaccompaniedonlybyasampleprograminPolish!).Initiallythemostusefulofthese(areconsult(filename),whichwillreadinanASCIItextfileoffactsandrules,listing('',filename)towriteallcurrentfactsandrulestoanamedfile,andedit,whichallowsinteractiveeditingofthecurrentdatabase.Some(English!)examplesshouldhavefoundtheirwayontothe disktoo,alongwithsomeusefulpredicatesforlistandscreenhandling,aswellasacopyofthisarticle.Inashortarticle,there<isnowherenearenoughspacetodescribethepowerofthisimportant<language.Butifthishasinterestedorintriguedyou,PROLOG80hasÜmadeitpossibletoexperimentwithalanguageofthefuture. Forfurtherreading:ThestandardtextonPROLOGistheClocksinandMellishbookProgramminginProlog,publishedbySpringerVerlag.Thisisanexpensivepaperback,(butshouldbeavailableinlargerlibraries.TheAugust1987issueofPthejournalBYTEcontainsanumberofarticlesonthelanguage,and<thereisaseriesof4tutorialarticlesinPersonalComputerWorld,FebruaryMay1987.