What does a hyphen at end of a term mean

自闭症网瘾萝莉.ら 提交于 2019-12-24 00:58:10

问题


I'm trying to understand the statement and I can't find any thing about the -1/4 at the the end of the object term. I've tried searching but I'm not even sure what to search for.

exists(A,object(B,A,apple,countable,na,eq,1)-1/4).

回答1:


The second argument of exists/2 are two terms in pair notation. One term being object(_A,A,apple,countable,na,eq,1) and the other being the 1/4. You can see this if you try the following query:

   ?- exists(A,X-Y).
X = object(_A,A,apple,countable,na,eq,1),
Y = 1/4

And since the second term is an arithmetic expression, you can evaluate it using is/2:

   ?- exists(A,X-Y), Z is Y.
X = object(_A,A,apple,countable,na,eq,1),
Y = 1/4,
Z = 0.25

The functor (-)/2 is often used to denote pairs. As pointed out by @lurker in the comments, the canonical form is -(X,Y) but since (-)/2 is defined as an infix operator in Prolog, both notations are equivalent. To see that consider the following query:

   ?- X-Y = -(X,Y).

true


来源:https://stackoverflow.com/questions/45090126/what-does-a-hyphen-at-end-of-a-term-mean

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