2

我正在使用 SWI-PROLOG 版本 6.6.6

我想打印特定谓词类型的所有属性。

我有一个名为 law 的谓词,数量为 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|...].

但是,即使在盗版重罪之后,还有更多的法律类型,它们并没有被打印到控制台上。我如何让它们打印出来?

4

1 回答 1

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。)

于 2014-11-27T19:20:41.837 回答