现在的位置: 首页 > 综合 > 正文

2008 October 29th Wednesday (十月 二十九日 水曜日)

2013年02月07日 ⁄ 综合 ⁄ 共 822字 ⁄ 字号 评论关闭
 %data
love(zhangxueyou, wanfei).
love(zhangxueyou, zouhuimin).
love(wanfei, xietinfen).
love(zouhuimin, zhangxueyou).
love(xietinfen, wanfei).
love(xietinfen, zouhuimin).
love(liudehua, zouhuimin).

%rules
lovers(X,Y) :- love(X,Y),love(Y,X).

%rival_in_love(X,Y) :- love(X,Z),not(love(Z,X)),love(Z,Y).
rival_in_love(X,Y) :- love(X,Z),love(Z,Y),X/=Y.

  The above is a example in prolog programming language.  I found that the "not" is ineffective in GNU Prolog.  So, I have to
modify the rule "rival_in_love" by using "/=".  Although, during developing I am aware that if we have "not" predicator we have
to adopt a non-natural or inconveniently way to slove our problem.

  I re-debuged the prolog example command_loop.  The following coding is also effective.  I changed the "X == 'end'" to "X = 'end'".
Yes, unification will resulte in success.

cmd_loop :-
  repeat,
  write('Enter command (end to exit): '),
  read(X),
  write(X),
  nl,
  X = 'end', !.

抱歉!评论已关闭.