Prolog列表未在控制台上打印所有元素 [英] Prolog list not printing all the elements on console

查看:102
本文介绍了Prolog列表未在控制台上打印所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SWI-PROLOG版本6.6.6

I am using SWI-PROLOG version 6.6.6

我要打印特定谓词类型的所有属性.

I want to print all the attributes of a particular predicate type.

我有一个谓词为arity 2的法律.

I have a predicate called law with arity 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').

现在,我想通过输入法律类型来访问法律. 例如

Now I want to access a law by entering its type. Such as,

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

This works perfectly. Now, I also want the user to know what all types of laws are there so that the user can enter it as a query to get the corresponding law. ex power(money).

为此,我进行了查询以获取所有这些关键字并将它们添加到列表中并显示该列表. 但是最终打印出来的列表并不完整.

For this, I made a query to get all these keywords and add them to a list and display the list. But the list that is finally printed is not complete.

powerList(L) :- findall(X,law(X,_), L).

我使用此代码来获取列表. 但是控制台上的输出是

I use this code to get the list. But the output on the console is

L = [borrow, commerce, unifomity, money, punishment, establishment, exclusiverights, court, piracyfelony|...].

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

But, there are more law types even after piracyfelony and they are not getting printed to the console. How do I get them printed?

推荐答案

这是Prolog顶级循环的功能,试图使输出简短.

This is a feature of Prolog's toplevel loops that tries to keep the output short.

要了解如何更改它,请询问Prolog支持哪个Prolog标志,该标志的值至少是两个元素的列表:

To find out how you might change it, ask which Prolog flags your Prolog supports that have a value being a list of at least two elements:

?- 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.)

(In newer versions starting with SWI 7 there is another flag value, answer_write_options.)

这篇关于Prolog列表未在控制台上打印所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆