Swi-Prolog中的冒号(:)代表什么? [英] What does the colon (:) exactly stand for in Swi-Prolog?

查看:109
本文介绍了Swi-Prolog中的冒号(:)代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

prolog .
在交互模式下,您可以看到以下证据:

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.

出于什么目的引入(:)?我在www中找不到任何详细信息. 似乎它提供了将递归结构称为List的另一种语法方式.

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, :).

是否可以列出所有此类隐式函子?

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

推荐答案

这是 module 限定符,您可以通过以下方式查看其声明:

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

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

模块是Prolog的重要扩展,大型程序特别需要此模块,但未符合ISO标准. SWI-Prolog(通常)对此具有务实的观点,并实现了一种有用的方法.

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 检查操作员,您会发现此片段很有用:

OT inspecting operators, you could find this snippet useful:

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

这篇关于Swi-Prolog中的冒号(:)代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆