How to use list constructors (./2) in SWI-Prolog

∥☆過路亽.° 提交于 2019-12-18 08:53:06

问题


I am trying to use list constructor in SWI-Prolog, but am getting 'dict' expected error.

For example,

.(a, []) == [a].

ERROR: Type error: `dict' expected, found `a' (an atom)
ERROR: In:
ERROR:   [11] throw(error(type_error(dict,a),_14808))
ERROR:   [10] '$type_error'(dict,a) at /Applications/SWI-Prolog.app/Contents/swipl/boot/init.pl:3369
ERROR:    [9] '$dicts':'.'(a,[],_14874) at /Applications/SWI-Prolog.app/Contents/swipl/boot/dicts.pl:46
ERROR:    [8] '<meta-call>'(user:(...,...)) <foreign>
ERROR:    [7] <user>
Exception: (9) '.'(a, [], _14200) ? 

Could anyone help me configure this functionality?


回答1:


SWI-Prolog 7.x uses a different list constructor, '[|]'/2, instead of the traditional ./2 Prolog constructor:

?- '[|]'(1,[]) == [1].
true.

The change was motivated to free ./2 for other uses, notably in dict terms, as hinted in the error message you got for your query.




回答2:


Better to use | in conventional notation,

?- X = '[|]'(1,[0]).
X = [1, 0].

can be write like this

?- X = [1|[0]].
X = [1, 0].


来源:https://stackoverflow.com/questions/44348509/how-to-use-list-constructors-2-in-swi-prolog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!