使用Prolog进行逻辑编程

时间:2018-03-03 07:21:39

标签: prolog logic

使用Prolog进行逻辑编程:

考虑该计划:

        f(X) :- !, X = a.
        f(X) :- !, X = b.
        f(X) :- X = c.

P分别为查询f(a),f(b)和f(c)返回什么?

考虑该计划:

        f(X) :- X = a, !.
        f(X) :- X= b, !.
        f(X) :- X = c.

P分别为查询f(a),f(b)和f(c)返回什么?

1 个答案:

答案 0 :(得分:0)

  

P分别为查询f(a),f(b)和f(c)返回什么?

  f(X) :- !, X = a.
  f(X) :- !, X = b.
  f(X) :- X = c.
?- f(a).
true.

?- f(b).
false.

?- f(c).
false.
   f(X) :- X = a, !.
   f(X) :- X = b, !.
   f(X) :- X = c.
?- f(a).
true.

?- f(b).
true.

?- f(c).
true.