0

我是一名大学生,对 Prolog 很陌生。我目前正在开发一个 C# 应用程序,它应该使用任何合适的 prolog-C# 库与 Prolog 集成。我发现Prolog.NET(由 Ali Hodroj 开发)对于我的场景来说是一个很好的解决方案,它也符合我的要求。但是,在使用它时查询特定谓词的替代解决方案时,我遇到了一些麻烦。例如,像这样的谓词,

add(X,Y,Ans) :- Ans is X+Y.

将只有一个特定的答案,如果用户分别为 X 和 Y 输入 1 和 2,则答案为 3。但,

female(maria). 
female(emma). 
parent(bobby, emma).
parent(bobby, maria). 
daughter(X,Y) :- parent(X,Y), female(Y).

如果daughter(X,Y)谓词被查询为daughter(bobby,D),则D将有两个值,emma和maria,可以通过按“;”进行迭代 在 Prolog 环境中。但是在 Prolog.NET 中使用 C# 时,我只能得到一个特定的值。例如:

AbstractTerm a = new AbstractTerm();
PrologClass proClass = new PrologClass();
proClass.daughter("bobby", a);

从 C# 环境调用上述女儿(X,Y)方法时,它只会返回一个特定的解决方案(emma),我需要的是获得另一个解决方案,即 maria。我已经尝试了很多事情,但无论如何我似乎都无法获得其他价值。如果有人能告诉我如何实现这一点,我将不胜感激!这对我的项目工作将是一个很大的帮助!

提前致谢!:)

4

1 回答 1

1

Actually not true, as this implemetation does not have bagof

Wrap the queries in bagof/3, like this:

bagof( (X,Y), daughter(X,Y), Result).

You should receive a list of all results. Look at the other predicates for finding all solutions to a goal for more options.

于 2013-03-23T15:42:55.727 回答