【问题标题】:Prolog list not printing all the elements on consoleProlog 列表未在控制台上打印所有元素
【发布时间】:2015-01-26 10:35:41
【问题描述】:

我使用的是 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|...].

但是,即使在盗版重罪之后,还有更多的法律类型,并且它们不会打印到控制台上。如何打印它们?

【问题讨论】:

  • SWI-Prolog 网站的常见问题解答为您提供答案:swi-prolog.org/FAQ/AllOutput.html
  • @PauloMoura:已过时 7
  • @false 问题以“我使用的是 SWI-PROLOG 6.6.6 版”开头。

标签: list prolog prolog-toplevel


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2014-01-17
    • 2023-03-09
    • 2015-03-16
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    相关资源
    最近更新 更多