Laman

Senin, 25 Oktober 2010

Example of How to Make Prolog


This is a simple example of how to make a prolog.
First, we must make the facts and rules. Rules and facts can be created using notepad. Examples of facts and rules:
husband(andy).
husband(roni).
wife(risa).
wife(amel).
loves(X,Y):-husband(X),wife(Y).
loves(X,y):-wife(X),husband(Y). 


 After that, click "save as" on the file menu.



 For easier, save the notepad on the desktop. Rename the file. Add ".pl" behind the name of the file. It is intended that the notepad can be opened using the prolog. Replace "save as type" to "all files" and click save.


Open the notepad that saved on the dekstop with "open with" prolog. after opened, type "consult('<name of the file>.pl')." example: consult('notepad prolog.pl'). after that, click "enter".


For example, you want to try the word "husband (X).", it will display one of (X), which is andy. If the answer was correct, automatically, Prolog will answer "yes." 


If you type "wife(Y).",it will display one of (Y), which is risa. If the answer was correct, automatically, Prolog will answer "yes."


if you type "loves(rony,amel).", automatically, prolog will answer "yes".
But if you type "loves(roni,andy)." , prolog will answer "no". Because the facts are not in accordance with the rules. in the rules, husband with wife loves it, not the husband with the husband, or wife with the wife.

 

Tidak ada komentar:

Posting Komentar