如何在 SWI-Prolog 中扩展结果列表?

发布于 2024-08-06 18:28:49 字数 171 浏览 5 评论 0原文

?- length(L,25).
L = [_G245, _G248, _G251, _G254, _G257, _G260, _G263, _G266, _G
269|...].

如果我在长度谓词后使用 write(L) ,那么解释器会打印列表两次,一次扩展,另一次不扩展。

?- length(L,25).
L = [_G245, _G248, _G251, _G254, _G257, _G260, _G263, _G266, _G
269|...].

If I use write(L) following the length predicate then the interpreter prints the list twice, one expanded and the other not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷遇一生 2024-08-13 18:28:49

深度有限制,防止输出过长。您可以使用 set_prolog_flag/1 更改它。

?- length(L, 25).
L = [_G257, _G260, _G263, _G266, _G269, _G272, _G275, _G278, _G281|...].

?- current_prolog_flag(toplevel_print_options, V).
V = [quoted(true), portray(true), max_depth(10), priority(699)].

?- set_prolog_flag(toplevel_print_options, [quoted(true), portray(true), max_depth(100), priority(699)]).
true.

?- length(L, 25).
L = [_G257, _G260, _G263, _G266, _G269, _G272, _G275, _G278, _G281, _G284, _G287, _G290, _G293, _G296, _G299, _G302, _G305, _G308, _G311, _G314, _G317, _G320, _G323, _G326, _G329].

编辑:您还可以通过从选项列表中删除该限制来完全删除该限制。

There is a limit on the depth to prevent too long output. You can change it with set_prolog_flag/1.

?- length(L, 25).
L = [_G257, _G260, _G263, _G266, _G269, _G272, _G275, _G278, _G281|...].

?- current_prolog_flag(toplevel_print_options, V).
V = [quoted(true), portray(true), max_depth(10), priority(699)].

?- set_prolog_flag(toplevel_print_options, [quoted(true), portray(true), max_depth(100), priority(699)]).
true.

?- length(L, 25).
L = [_G257, _G260, _G263, _G266, _G269, _G272, _G275, _G278, _G281, _G284, _G287, _G290, _G293, _G296, _G299, _G302, _G305, _G308, _G311, _G314, _G317, _G320, _G323, _G326, _G329].

Edit: You can also remove the limit completely by removing it from the options list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文