如果我在Prolog中使用这样的东西
test(X/Y).
或
test(X:Y).
那么X:Y
和X/Y
被视为变量还是字符串?
我们可以把它放在什么类别?
答案 0 :(得分:4)
X/Y
和X:Y
都是复合词。尝试:
?- functor(X/Y, Functor, Arity).
Functor = (/),
Arity = 2.
?- X/Y =.. [Functor| Arguments].
Functor = (/),
Arguments = [X, Y].
?- functor(X:Y, Functor, Arity).
Functor = (:),
Arity = 2.
?- X:Y =.. [Functor| Arguments].
Functor = (:),
Arguments = [X, Y].
/
和:
都是标准的中缀运算符:
?- current_op(Priority, Type, /).
Priority = 400,
Type = yfx.
?- current_op(Priority, Type, :).
Priority = 600,
Type = xfy.
类型yfx
表示运算符 left-assotiative :
?- write_canonical(x/y/z).
/(/(x,y),z)
true.
虽然类型xfy
表示运算符正确的:
?- write_canonical(x:y:z).
:(x,:(y,z))
true.