2

if I use something like this in Prolog

test(X/Y).

or

test(X:Y).

So X:Y and X/Y are considered as a variable, or as a string?

In what category we can put it?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Emily
  • 23
  • 4

1 Answers1

4

Both X/Yand X:Y are compound terms. Try:

?- 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].

Both / and : are standard infix operators:

?- current_op(Priority, Type, /).
Priority = 400,
Type = yfx.

?- current_op(Priority, Type, :).
Priority = 600,
Type = xfy.

The type yfx means that the operator is left-assotiative:

?- write_canonical(x/y/z).
/(/(x,y),z)
true.

While the type xfy means that the operator is right-assotiative:

?- write_canonical(x:y:z).
:(x,:(y,z))
true.
Paulo Moura
  • 18,373
  • 3
  • 23
  • 33