为什么这不起作用?
?- '.'(a,[]).
ERROR: Unknown procedure: ('.')/2
ERROR: However, there are definitions for:
ERROR: ('.')/3
false.
?- .(a,[]).
ERROR: Unknown procedure: ('.')/2
ERROR: However, there are definitions for:
ERROR: ('.')/3
false.
?- .(a,[]) == [a].
ERROR: Type error: `dict' expected, found `a' (an atom)
ERROR: In:
ERROR: [13] throw(error(type_error(dict,a),_13228))
ERROR: [10] '<meta-call>'(user:user: ...) <foreign>
ERROR: [9] toplevel_call(user:user: ...) at /usr/lib/swi-prolog/boot/toplevel.pl:1158
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
不确定这实际上有多相关,但根据文献,这应该是正确的。 SWI 有不同的谓词/过程吗?
正如评论中链接的那样,SWI Prolog 文档说:
用于创建列表单元格的“cons”运算符已从漂亮的原子
更改为丑陋的原子‘.’
,因此我们可以将‘[|]’
用于其他目的,特别是字典上的函数符号。请参阅第 5.4.1 节。‘.’
这意味着 SWI 7+ 中相当于传统
.(a,.(b,[]))
的是:
?- X = '[|]'(a, '[|]'(b, [])).
X = [a, b]
SWI prolog 不支持
.
表示法。
相反,只有一个元素的列表表示为 [A]
,而具有头 H 和尾 T 的列表表示为 [H|T]
,例如
?- X = [1 | [2,3,4]]
X = [1,2,3,4]