天天看点

Prolog基本程序

编辑下面代码;

male(di).
male(jianbo).
female(xin).
female(yuan).
female(yuqing).
father(jianbo,di).
father(di,yuqing).
mother(xin,di).
mother(yuan,yuqing).
grandfather(X,Y):-father(X,Z),father(Z,Y).
grandmother(X,Y):-mother(X,Z),father(Z,Y).
daughter(X,Y):-father(X,Y),female(Y).
           

存为father.pl;存到swi-prolog的bin目录下;据说此程序描述了 谁是谁的爸爸 的问题;我还不太了解它的语法;prolog程序的后缀名为pl;

进入swi-prolog;使用consult来编译保存的pl文件;出现下图提示,编译成功;

Prolog基本程序

语法还不熟悉;prolog变量是大写字母开头;输入下图语句,然后;prolog告诉你,”yuqing”的祖父是”jianbo”; 

Prolog基本程序

    有空继续学习它的语法和基本语句;如果能用这语言编一个故障诊断程序也是很棒的;

继续阅读