CSC302 2011S Programming Languages
[Skip to Body]
Admin:
[Front Door]
[Schedule]
[Handouts]
[Honesty]
[Piazzza]
Current:
[Current Outline]
[Current EBoard]
[Current Assignment]
[Current Lab]
[Current Reading]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
[Reference]
Languages:
[Clojure]
[Erlang]
[Haskell]
[Io]
[Prolog (GNU)]
[Ruby]
[Scala]
Misc:
[SamR]
[CSC302 2007S]
[7L7W]
Summary: We begin our exploration of the Prolog programming language.
Prerequisites: Sections 4.1 and 4.2 of Tate. Experience with Linux.
Contents:
Create a directory for the lab.
a. Try Tate's food example and see if it behaves as advertised.
b. Add the following two rules.
flavor(salty, cracker). flavor(crunchy, cracker).
Then, determine what flavors a ritz has.
c. Try a few more experiments that you design.
a. Try Tate's map-coloring example and see if it behaves as advertised.
b. What happens if you don't accept the first result from Prolog? (Keep rejecting results and see what happens.)
Consider the following modification of Tate's food program, which has been extended to print out some information about the rule being applied.
food_type(velveeta, cheese) :- write(rule1), nl. food_type(ritz, cracker) :- write(rule2), nl. food_type(spam, meat) :- write(rule3), nl. food_type(sausage, meat) :- write(rule4), nl. food_type(jolt, soda) :- write(rule5), nl. food_type(twinkie, dessert) :- write(rule6), nl. flavor(sweet, dessert) :- write(rule7), nl. flavor(savory, meat) :- write(rule8), nl. flavor(savory, cheese) :- write(rule9), nl. flavor(sweet, soda) :- write(rule10), nl. food_flavor(X, Y) :- write(rule11), food_type(X, Z), flavor(Y, Z).
a. Load this file and then try a few queries to see the order in which the Prolog interpreter applies rules.
b. Reverse the order of the two preconditions of food_flavor
and see what effect this has on the order in which the Prolog interpreter
applies rules.
Here's the start of some rules about a family tree.
related(X,Y) :- ancestor(X,Y). related(X,Y) :- ancestor(Y,X). related(X,Y) :- ancestor(Z,Y), ancestor(Z,X). ancestor(X,Y) :- parent(X,Y). ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y). parent(alice,bob). parent(alice,bill). parent(andrew,bob). parent(andrew,bill). parent(andrew,brianna). parent(amy,bo). parent(bob,charles). parent(billie,charles). parent(charles,david). parent(charisma,david). parent(bo,carlene). parent(carlene,darlene).
a. Determine all of David's parents.
b. Determine all of Darlene's ancestors.
c. Write some queries of your own.
d. Extend the database.
Add write and nl predicates to our family
database and trace some interesting queries.
Tuesday, 8 February 2011 [Samuel A. Rebelsky]
Wednesday, 9 February 2011 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC302/2011S/Labs/prolog-1.html.
[Skip to Body]
Admin:
[Front Door]
[Schedule]
[Handouts]
[Honesty]
[Piazzza]
Current:
[Current Outline]
[Current EBoard]
[Current Assignment]
[Current Lab]
[Current Reading]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
[Reference]
Languages:
[Clojure]
[Erlang]
[Haskell]
[Io]
[Prolog (GNU)]
[Ruby]
[Scala]
Misc:
[SamR]
[CSC302 2007S]
[7L7W]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Mon Apr 25 08:06:49 2011.
The source to the document was last modified on Wed Feb 9 09:31:17 2011.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC302/2011S/Labs/prolog-1.html.
A PDF version of this document may be found at
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC302/2011S/Labs/prolog-1.pdf
You may wish to
validate this document's HTML
;
;