170 likes | 550 Views
QuickStart Prolog. Learning to Program in Prolog Richard Banister November 9, 2005. What is Prolog?. A Logical Programming Language Why logical? Created by Robert Kowalski and Alain Colmerauer sometime around 1972. Original intended for natural language parsing
E N D
QuickStart Prolog Learning to Program in Prolog Richard Banister November 9, 2005
What is Prolog? • A Logical Programming Language • Why logical? • Created by Robert Kowalski and Alain Colmerauer sometime around 1972. • Original intended for natural language parsing • Now used in AI, expert systems Applied Computing Technology Laboratory
The Logical Paradigm • Based on logical reasoning • Execution as mathematical proof • Non-sequential design • Fun! Applied Computing Technology Laboratory
Prolog as a Logical Language • Predicates are entered into a “database” • Rules are created • Queries are run against said predicates and rules • Results are determined only from what is known to be true • Well, how do we “do” anything? Applied Computing Technology Laboratory
A Logical Example • Take this example: cat(Timmy).legs(cat, 4).?- legs(Timmy, 4)yes • Yeah! • We can also do useful stuff Applied Computing Technology Laboratory
Prolog Advantages • It’s a Logical Programming language • It’s the only game in town • That’s about it. Applied Computing Technology Laboratory
Prolog Disadvantages • Limited sphere of usefulness • Not a “pure” logical language • It don’t have the fancy graphics the youngsters are raving about • It won’t make you popular with the ladies Applied Computing Technology Laboratory
Java or Prolog? • Kind of a silly question • Depends greatly on project goal • Prolog for web app = not a good idea • Java for robot army = maybe not a good idea either • Yet they are being combined together as we speak Applied Computing Technology Laboratory
Prolog Specification • Well, it’s a funny story • Prolog spec available… for a price • Grammar is not reprintable on web • Decidedly geek-non-friendly • This, along with late spec publication (1995!), may be why Prolog hasn’t taken over the world? • But we do know some things about the grammar Applied Computing Technology Laboratory
Prolog Grammar • A free approximate grammar can be found online: (https://www.freytag.us/twiki/bin/view/Freytag/ISOStandardPrologGrammar) • Here’s a sample: • Possibly not complete, but note simplicity Applied Computing Technology Laboratory
Is Prolog “Dead?” • Not quite. Still kicking in AI • New extensions are being developed: • Visual Prolog • Prova Applied Computing Technology Laboratory
Language Specifics Predicate:A statement given to be true ex. cat(Timmy). Rule:A method for proving future resultsex. cat(X) :- legs(4, X), whiskers(X), intent_to_destroy(X). Query:A request to prove a resultex. whiskers(Uncle Jerry). Intent_to_destroy(Uncle Jerry). Legs(1, Uncle Jerry). ?- cat(Uncle Jerry). no Applied Computing Technology Laboratory
Step 0: Getting Started • Get to know logical programming and Prolog • There are many websites that contain useful, if cryptic, Prolog information. Applied Computing Technology Laboratory
Step 1: Really Getting Started • Download & install GNU interpreter:http://pauillac.inria.fr/~diaz/gnu-prolog/ • You can get the source, too, if you really want it • Read up… the GNU interpreter isn’t easy Applied Computing Technology Laboratory
Step 2: Writing • Create a plain text file • Some editors have context-sensitive highlighting, but it’s probably not necessary • File should contain predicates and rules, not queries • Create a legendary, essential logical application (maybe, dog(Rover)?) Applied Computing Technology Laboratory
Step 3: Import Source File • Start the interpreter. • Use the consult command (or shortcut) to open and compile the source codeex. consult(‘/projects/prolog/cat.pl’). • Note the use of Unix-style file reference. This isn’t necessarily “documented” in the help file. • Assuming no errors, run queries on your program Applied Computing Technology Laboratory
Learning more about Prolog • Visit the QuickStart Languages web sitehttp://actlab.csc.villanova.edu/quickstart • Read up on logical languageshttp://en.wikipedia.org/wiki/Logic_programming • Devote your life to this tutorialhttp://web.archive.org/web/20041028043137/http://cs.wwc.edu/~cs_dept/KU/PR/Prolog.html Applied Computing Technology Laboratory