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.
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) Read more...