如何在 SWI-Prolog 中保存所有可能的解决方案? [英] How do you save all possible solutions in SWI-Prolog?

查看:40
本文介绍了如何在 SWI-Prolog 中保存所有可能的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约有一千种可能性的谓词,我需要所有的可能性作为输出.不可能简单地在 Windows 上的 SWI-Prolog 中复制和粘贴所有列出的可能性,因为您只能向上滚动这么多.

I have this predicate that has about a thousand possibilities and I need all possibilities as an output. It is not possible to simply copy and paste all listed possibilities in SWI-Prolog on Windows since you can only scroll up so much.

我的谓词如下所示:

?- question(X,Y,Z).
X = 'Fo',
Y = 'Ob',
Z = 'Ar' ;
X = 'Fo2',
etc...

我想知道是否有办法将结果保存在文件中?

I was wondering if there was a way to save the result in a file or something?

推荐答案

你可以这样使用:

main :-
    tell('output.txt'),
    (
        question(X,Y,Z),
        writeln([X, Y, Z]),
        fail
    ;
        told
    ).

或者您可以在 Prolog 中运行查询 ( question(X,Y,Z), writeln([X, Y, Z]), fail ; true ). 并在标准下获得所有解决方案输出(屏幕).

Or you can run the query ( question(X,Y,Z), writeln([X, Y, Z]), fail ; true ). in Prolog and get all solutions at standard output (screen).

这篇关于如何在 SWI-Prolog 中保存所有可能的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆