开发者

Simple Prolog program

I'm trying to teach myself some Prolog so that I can determine its fitness for solving a problem I have. Essentially the problem is, given a bunch of rules about the interaction between items, determine what items are available, unavailable, selected, and not selected.

But I'm failing at even the most simple parts! I drastically reduced the problem size just to see what I could do. Bel开发者_开发技巧ow is my knowledge base:

selected(A) :- implied(A).
implied(B) :- implies(A,B),selected(A).

implied(option_one).
implies(option_one,option_two).

And when I query:

selected(X).

I only get back option_two.

It seems like there is something very basic that I'm not understanding here, but it seems to me that if option_one should also come back in that list (especially since one of the facts is 'implied(option_one)'.

If it matters, I've tried this using P# as well as SWI-Prolog, which give the same result.


When u have your first answer X = option_two press ; to get next answer

?- selected(X).
X = option_two ;
X = option_one.

Or u may use smth like that for showing all matching things:

?- selected(X), writeln(X), fail.
option_two
option_one
false.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜