Friday, October 23, 2009

Fact, Rules, Predicate, and Variable in Prolog

Now, We will show another tutorial about Prolog.

This is a program about searching anything which have same identify. We will use this source :

/* 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).

Step 1

Type the source to text editor (ex. notepad).

See this image :








(Click the image if you can't see well)


Step 2

Save in My Documents\Prolog\ and give name "animal.pl" or "animal.pro".

See this image :










(Click the image if you can't see well)



Step 3

Open it with command consult.

See this image :










(Click the image if you can't see well)


Step 4

Now, if We want to search all mammal animal, use this command : animal(mammal,A,_,_). "A" is variable. Can change another variable, but must in Upper Case.

Note : "_" mean DON'T SHOW anything from source in the line which can possibility show.

See this image :
















(Click the image if you can't see well)


Step 5

Now, if We want to search all the carnivores that are mammals, use this command : animal(mammal,A,carnivore,_).

See this image :
















(Click the image if you can't see well)


Step 6

Now, if We want to search all mammals with stripes, use this command : animal(mammal,A,_,stripe).

See this image :
















(Click the image if you can't see well)


Step 7

Now, if We want to search a reptile that has a mane, use this command : animal(_,A,_,_mane).

See this image :
















(Click the image if you can't see well)

0 comments:

Post a Comment

About This Blog

This Blog created to complete Discrete Math Assignment. This Blog contain all about discrete math subject especially Prolog programming. The member of team are Fahri Reza, Izzat, Chandra and Catur. We are from Discrete Math class A at Information System Department faculty of Information Technology INSTITUT TEKNOLOGI SEPULUH NOPEMBER (ITS) Surabaya. We hope all existing posts on this blog will be useful for all people. And thanks for visiting our Blog..

Followers

  © Blogger template PingooIgloo by Ourblogtemplates.com 2009 | The Permutation Team's Blog 2009

Back to TOP