SWI-Prolog - 显示长列表

发布于 2024-12-17 14:52:11 字数 148 浏览 1 评论 0原文

我正在使用 SWI-Prolog,我正在尝试打印一个列表,但如果该列表有超过 9 个项目 - 它看起来像那样 -

[1, 15, 8, 22, 5, 19, 12, 25, 3|...] 

有没有办法显示整个列表?

I'm using SWI-Prolog and I'm trying to print a list but if the list has more than 9 items - it look like that -

[1, 15, 8, 22, 5, 19, 12, 25, 3|...] 

is there a way to show the whole list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

送君千里 2024-12-24 14:52:12

看一下:http://www.swi-prolog.org/FAQ/AllOutput。 html

简单的解决方案是在给出答案后键入 w,即:

?- n_queens_problem(10,X).
X = [1, 3, 6, 8, 10, 5, 9, 2, 4|...] [write]
X = [1, 3, 6, 8, 10, 5, 9, 2, 4, 7] 

按下“w”键后,末尾会显示“[write]”,并且完整的解决方案出现在下一行。

Have a look at: http://www.swi-prolog.org/FAQ/AllOutput.html

The simple solution is to type w after the answer is given, i.e.:

?- n_queens_problem(10,X).
X = [1, 3, 6, 8, 10, 5, 9, 2, 4|...] [write]
X = [1, 3, 6, 8, 10, 5, 9, 2, 4, 7] 

After you have pressed the "w"-key "[write]" is displayed at the end and the full solution appears in the next line.

安静 2024-12-24 14:52:12

我找到了两种方法。


1.

?- set_prolog_flag(answer_write_options,[max_depth(0)]).
true.

然后执行打印截断列表的命令。

(set_prolog_flag 文档)


2.

?- atom_chars(goodbye_prolog, X) ; true.

(AllOutput 文档)

Put ; true. 在调用结束时会生成一个长列表。然后按键盘上的 w 键。结果是:

?- sudoku([_,_,2,3,_,_,_,_,_,_,_,_,3,4,_,_], Solution); true.
Solution = [4, 1, 2, 3, 2, 3, 4, 1, 1|...] [write]
Solution = [4, 1, 2, 3, 2, 3, 4, 1, 1, 2, 3, 4, 3, 4, 1, 2] ;
true.

I've found two ways.


1.

?- set_prolog_flag(answer_write_options,[max_depth(0)]).
true.

Then do your command that is printing a truncated list.

(set_prolog_flag documentation)


2.

?- atom_chars(goodbye_prolog, X) ; true.

(AllOutput documentation)

Put ; true. at the end of the call that results in a long list. Then push the w key on your keyboard. The result is:

?- sudoku([_,_,2,3,_,_,_,_,_,_,_,_,3,4,_,_], Solution); true.
Solution = [4, 1, 2, 3, 2, 3, 4, 1, 1|...] [write]
Solution = [4, 1, 2, 3, 2, 3, 4, 1, 1, 2, 3, 4, 3, 4, 1, 2] ;
true.
太阳哥哥 2024-12-24 14:52:12

如果 prolog 仅返回一个答案,您可以通过键入“; true”使其等待。在谓语之后。然后,如果您按“w”,您将看到文档中编写的整个列表: http://www.swi-prolog.org/FAQ/AllOutput.html

If prolog returns only one answer, you can make it wait by typing "; true." after the predicate. Then, if you press "w", you will get to see the whole list as written in the doc : http://www.swi-prolog.org/FAQ/AllOutput.html

青柠芒果 2024-12-24 14:52:12
?- createListSomehow(List), print(List), nl.

会做得足够整洁。这就是我所做的。

变体:

?- use_module(library(pprint)). %load a library to do pretty-printing
?- createListSomehow(List), print_term(List,[]), nl.

print_term[] 参数是一个(空)选项列表。有关详细信息,请参阅文档

?- createListSomehow(List), print(List), nl.

will do it neatly enough. That's what I do.

Variation:

?- use_module(library(pprint)). %load a library to do pretty-printing
?- createListSomehow(List), print_term(List,[]), nl.

The [] argument to print_term is an (empty) list of options. For more information, see documentation.

§对你不离不弃 2024-12-24 14:52:12

如果您希望 SWI-Prolog 默认显示整个列表,您可以将此行添加到您的 init 文件

:- set_prolog_flag(answer_write_options,[max_depth(0)]).

您可以从 GUI 轻松修改 init 文件(设置 => 用户 init 文件)。

If you want that SWI-Prolog will show the whole list by default you can add this line to your init file:

:- set_prolog_flag(answer_write_options,[max_depth(0)]).

You can modify the init file easily from the GUI (Settings => User init file).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文