syntaxprolognomenclature

In what category can we put X/Y or X:Y in Prolog


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?


Solution

  • 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.