以 'raw' ./2 格式显示列表
Display a list in its 'raw' ./2 format
是否可以以 ./2 格式显示 Prolog 列表,例如
对于列表:
| ?- L=[a,b,c].
L = [a,b,c] ?
yes
有没有办法显示:
L = .(a, .(b, .(c, []))).
通常,write_canonical(List)
或 ?- write_term(List, [quoted(true), ignore_ops(true)])
,正如评论中指出的那样。由于 SWI-Prolog 决定 do things differently,这还不够好:
?- write_canonical([a]).
[a]
true.
?- write_term([a], [quoted(true), ignore_ops(true)]).
[a]
true.
?- write_term([a], [dotlists(true)]).
.(a,[])
true.
查看documentation on write_term/2
,注意选项brace_terms(Bool)
和dotlists(Bool)
。但要注意:如果你正常启动 SWI-Prolog 7,./2
不再是列表仿函数!
?- L = .(a, []).
ERROR: Type error: `dict' expected, found `a' (an atom) % WHAT?
?- L = '[|]'(a, []).
L = [a].
如果您从 swipl --traditional
开始,一切都会恢复正常,有点像:
$ swipl --traditional
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.4-32-g9311e51)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- L = .(a, []).
L = [a].
您仍然无法使用 write_canonical(List)
或 write_term(List, [quoted(true), ignore_ops(true)])
。
阅读 SWI-Prolog 文档的链接部分了解详细信息和基本原理。作为建议,如果您决定使用 SWI-Prolog,请坚持使用默认设置的 SWI-Prolog 7,并且仅在需要与另一个 Prolog 实现通信时才使用 write_term(List, [dotlists(true)])
。通常的列表表示法 [a, b, ...]
在大多数常规情况下应该足够好。
是否可以以 ./2 格式显示 Prolog 列表,例如
对于列表:
| ?- L=[a,b,c].
L = [a,b,c] ?
yes
有没有办法显示:
L = .(a, .(b, .(c, []))).
通常,write_canonical(List)
或 ?- write_term(List, [quoted(true), ignore_ops(true)])
,正如评论中指出的那样。由于 SWI-Prolog 决定 do things differently,这还不够好:
?- write_canonical([a]).
[a]
true.
?- write_term([a], [quoted(true), ignore_ops(true)]).
[a]
true.
?- write_term([a], [dotlists(true)]).
.(a,[])
true.
查看documentation on write_term/2
,注意选项brace_terms(Bool)
和dotlists(Bool)
。但要注意:如果你正常启动 SWI-Prolog 7,./2
不再是列表仿函数!
?- L = .(a, []).
ERROR: Type error: `dict' expected, found `a' (an atom) % WHAT?
?- L = '[|]'(a, []).
L = [a].
如果您从 swipl --traditional
开始,一切都会恢复正常,有点像:
$ swipl --traditional
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.4-32-g9311e51)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- L = .(a, []).
L = [a].
您仍然无法使用 write_canonical(List)
或 write_term(List, [quoted(true), ignore_ops(true)])
。
阅读 SWI-Prolog 文档的链接部分了解详细信息和基本原理。作为建议,如果您决定使用 SWI-Prolog,请坚持使用默认设置的 SWI-Prolog 7,并且仅在需要与另一个 Prolog 实现通信时才使用 write_term(List, [dotlists(true)])
。通常的列表表示法 [a, b, ...]
在大多数常规情况下应该足够好。