>如果我在Prolog中使用类似的东西
test(X/Y).
或
test(X:Y).
那么X:Y
和X/Y
被视为变量还是字符串?
我们可以把它放在什么类别中?
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
表示运算符是左关联运算符:
?- write_canonical(x/y/z).
/(/(x,y),z)
true.
虽然类型xfy
表示运算符是右关联运算符:
?- write_canonical(x:y:z).
:(x,:(y,z))
true.