我正在使用SWI-PROLOG版本6.6.6
我想打印特定谓词类型的所有属性。
我有一个叫做法律的谓词2。
有些事实是
law(borrow,'To borrow Money on the credit of the United States').
law(commerce,'To regulate Commerce with foreign Nations, and among the several States, and with the Indian Tribes').
law(unifomity,'To establish an uniform Rule of Naturalization, and uniform Laws on the subject of Bankruptcies throughout the United States').
law(money,'To coin Money, regulate the Value thereof, and of foreign Coin, and fix the Standard of Weights and Measures').
law(punishment,'To provide for the Punishment of counterfeiting the Securities and current Coin of the United States').
law(establishment,'To establish Post Offices and post Roads').
law(exclusiverights,'To promote the Progress of Science and useful Arts, by securing for limited Times to Authors and Inventors the exclusive Right to their respective Writings and Discoveries').
law(court,'To constitute Tribunals inferior to the supreme Court').
等
现在我想通过输入类型来访问法律。 如,
power(X) :- law(X,Y), display('\nCongress has the power : '),display(Y).
powers(ALL) :- display('\nCongress has the powers : '), law(_,Y), display('\n'), display(Y).
这完美无缺。现在,我还希望用户知道所有类型的法律是什么,以便用户可以输入它作为查询以获得相应的法律。
前power(money).
为此,我进行了查询以获取所有这些关键字并将它们添加到列表中并显示列表。 但最终打印的列表并不完整。
powerList(L) :- findall(X,law(X,_), L).
我使用此代码获取列表。 但是控制台上的输出是
L = [borrow, commerce, unifomity, money, punishment, establishment, exclusiverights, court, piracyfelony|...].
但是,即使在piracyfelony之后还有更多的法律类型,并且他们没有被打印到控制台。我如何打印它们?
答案 0 :(得分:2)
这是Prolog的顶级循环的一个功能,它试图保持输出短路。
要了解如何更改它,请询问Prolog支持哪些Prolog标志,其值为至少两个元素的列表:
?- current_prolog_flag(F,Options), Options = [_,_|_].
F = debugger_print_options,
Options = [quoted(true), portray(true), max_depth(10), attributes(portray), spacing(next_argument)] ;
F = toplevel_print_options,
Options = [quoted(true), portray(true), max_depth(10), spacing(next_argument)] ;
F = argv,
Options = [swipl, '-f', none] ;
false.
现在相应地修改它:
?- length(L,10).
L = [_G303, _G306, _G309, _G312, _G315, _G318, _G321, _G324, _G327|...].
?- set_prolog_flag(toplevel_print_options,[quoted(true), portray(true), max_depth(0), spacing(next_argument)]).
true.
?- length(L,10).
L = [_G303, _G306, _G309, _G312, _G315, _G318, _G321, _G324, _G327, _G330].
(在以SWI 7开头的较新版本中,还有另一个标志值answer_write_options
。)