Kamis, 22 Oktober 2009

Fact, Rules, Predicate, and Variable in Prolog

Hellooo .. this is our Final Project on Third Week.
Lets do the exercise on Logic Programming using Prolog e-book Page 27.

Exercise no. 1
Type the following program into a file and load it into Prolog.

/* Animals Database */
animal(mammal,tiger,carnivore,stripes).
animal(mammal,hyena,carnivore,ugly).
animal(mammal,lion,carnivore,mane).
animal(mammal,zebra,herbivore,stripes).
animal(bird,eagle,carnivore,large).
animal(bird,sparrow,scavenger,small).
animal(reptile,snake,carnivore,long).
animal(reptile,lizard,scavenger,small).



Instructions : Devise and test goals to find (a) all the mammals, (b) all the carnivores that are
mammals, (c) all the mammals with stripes, (d) whether there is a reptile that has a mane.


Answer :

Step 1 . write down the following program to notepad, and save as .pl file. For this exercise, we will save it as numberone.pl



 Step 2 . Open your Prolog, click File>Consult and find the file you’ve just saved it. After you successfully open it, Prolog will show to you a successful quote like this image above.



Step 3 . First Question : find all mammals. just type ..
 animal(mammal,X,Y,Z).
   


Step 4 . for the second question : find all the carnivores that are
mammals. type ..

animal(mammal,X,carnivore,Z). 



3 comments:

Willy mengatakan...

i can copy ur post . . .

Willy mengatakan...

thanks . . .

Widya. Riza. Dita. Sari. mengatakan...

hheheheheeeww. you are welcome :)

Posting Komentar