我正在使用 SWI-Prolog,想要打印一个列表,但是如果列表有超过9个项目——它看起来像这样——
[1, 15, 8, 22, 5, 19, 12, 25, 3|...]
有没有一种方法可以显示整个列表?我正在使用 SWI-Prolog,想要打印一个列表,但是如果列表有超过9个项目——它看起来像这样——
[1, 15, 8, 22, 5, 19, 12, 25, 3|...]
有没有一种方法可以显示整个列表?请看: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]”,并且完整的解决方案会在下一行显示。
我找到了两种方法。
1.
?- set_prolog_flag(answer_write_options,[max_depth(0)]).
true.
然后执行打印截断列表的命令。
2.
?- atom_chars(goodbye_prolog, X) ; true.
在调用产生长列表的末尾添加; 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.
?- createListSomehow(List), print(List), nl.
我会做好足够整洁的工作。这就是我的职责。
变化:
?- use_module(library(pprint)). %load a library to do pretty-printing
?- createListSomehow(List), print_term(List,[]), nl.
print_term
函数的 []
参数是一个(空)选项列表。欲知详情,请参阅文档。
:- set_prolog_flag(answer_write_options,[max_depth(0)]).
?- solution(S) ; true.
,即只需在查询结尾添加; true
来引入一个选择点。这样一来,你还有机会按下w
键。 - mat