What does the colon (:) exactly stand for in Swi-Prolog?

房东的猫 提交于 2019-12-23 09:32:31

问题


I could not find explicitly what (:) stands for in prolog.
In interactive mode you can see the following evidence:

?- display(a:b).
:(a,b)
true.

?- display([a,b,c]).
.(a,.(b,.(c,[])))
true.

?- display(a:b:c:[]).
:(a,:(b,:(c,[])))
true.

?- a:b:REST = a:TAIL.
TAIL = b:REST.

For what purpose (:) is introduced? I could not find any details for it in www. Seems that it gives another syntactic way of talking about recursive structures as Lists.

We can say that it is Right-associative, what is its priority number?

:-op(??, xfy, :).

Is there a way to list all such kind of implicit functors?

listing(op). %of course this does not work

回答1:


That's the module qualifier, you can see its declaration with this:

?- current_op(X,Y,:).
X = 600,
Y = xfy.

Modules are an important extension to Prolog, particularly required for large programs, but miss from ISO standard. SWI-Prolog has (as usually) a pragmatic viewpoint on this, and implements an useful approach.

OT inspecting operators, you could find this snippet useful:

oplist :-
    setof((A,C,B), current_op(A,B,C), L),
    maplist(writeln, L).


来源:https://stackoverflow.com/questions/12759700/what-does-the-colon-exactly-stand-for-in-swi-prolog

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