如何处理序言列表?
我有谓词 m(L,L)
并且我希望它返回它所需要的列表。 代码是这样的:
m([],[]).
m([H|T],[H|L]) :- m(T,L).
当我尝试在这个例子中使用它时:
m([1,2,3,4,5,6,7,8,9,10],L)
我得到这个作为答案:(
L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...].
我注意到,如果我用更少的元素尝试它,那就可以了。)为什么会发生这种情况并且列表未完成?
我怎样才能避免这种情况?
抱歉,如果这是一个非常愚蠢的问题,但我搜索过网络,但找不到任何可以帮助我理解的文档...... 谢谢你!
I have the predicate m(L,L)
and I want it to return the list that it takes.
The code is this :
m([],[]).
m([H|T],[H|L]) :- m(T,L).
When I try to use it with this example :
m([1,2,3,4,5,6,7,8,9,10],L)
I get this as an answer :
L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...].
(I noticed that if I try it with less elements its ok.) why is this happening and the list is unfinished?
How can I avoid this?
Sorry if its a really stupid question but I've searched the web and I couldn't find any documentation that can help me understand...
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
列表已完成 - 输出只是为了可视化目的而被截断。如果您编写一个打印列表的谓词,您将看到它是完整的。我猜您正在使用 SWI prolog,这意味着您可以查看 此链接了解更改显示设置的方法。
The list is finished - the output is just getting truncated for visualization purposes. If you write a predicate that prints out your list, you'll see that it's complete. I'm guessing you're using SWI prolog, which means you can check out this link for ways to change the display settings.
作为调试器的顶层查询/应答循环都缩写了长而复杂的术语。他们这样做是为了避免无休止的输出页面。事实上,他们使用 write_term/3 进行编写,它带有一个选项- 列表作为参数。 Prolog 顶层打印的答案的选项列表位于 prolog 标志 toplevel_print_options 中,调试器的选项列表位于 debugger_print_options 中。最初两者的值如下:
要更改默认设置:
在您的 prolog 个人初始化文件中添加 set_prolog_flag/2 指令(请参阅 PlInitialization)更改上述 prolog 标志的默认值。
只需转到
设置 -> user init file ... ->
并像这样更改 max_depth(10):
您还可以在 PlInitialization 文件已被注释。
Both the toplevel query/answer loop as the debugger abbreviate long complex terms. They do this to avoid endless pages of output. In fact, they write using write_term/3 which takes an option-list as argument. The option list for answers printed by the Prolog toplevel is in the prolog-flag toplevel_print_options and the one for the debugger is in debugger_print_options. Initially both have the value given below:
To change the default settings:
Add a set_prolog_flag/2 directive in your prolog personal initialisation file (see PlInitialisation) to change the default the above mentioned prolog flags.
Just go to the
settings -> user init file ... ->
And change max_depth(10) like this:
There also other options you can use in PlInitialisation file that are commented already.