在Prolog

时间:2018-06-02 21:26:25

标签: syntax prolog nomenclature

如果我在Prolog中使用这样的东西

test(X/Y).

test(X:Y).

那么X:YX/Y被视为变量还是字符串?

我们可以把它放在什么类别?

1 个答案:

答案 0 :(得分:4)

X/YX: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.