Arity 3 statement in Prolog

In Prolog, how can I define the “relation” operator to work as a predicate of the / 3 relation? For example:

relation a b c.

and produce it:

relation(a, b, c).

Thanks!

+4
source share
1 answer

First of all, operators are not relations, and they are not predicates. Operators are a syntax function, they are there to help us save on a set of parentheses:

:- op(250,xfy,#).

and then

4 ?- X = 2#3#5, write_canonical(X).
#(2,#(3,5))
X = 2#3#5.

Now you can define a predicate that will handle complex terms as you like. This, of course, is not much different from

5 ?- X=[2,3|5], write_canonical(X).
'.'(2,'.'(3,5))
X = [2, 3|5].

. , , .

7 ?- Y=2#3#5#7, write_canonical(Y).
#(2,#(3,#(5,7)))
Y = 2#3#5#7.

:

:- op(250,xfx,#).
:- op(350,xfx,@).

10 ?- X=2@3#5, write_canonical(X).
@(2,#(3,5))
X = 2@3#5.

11 ?- X=2@3#5#7, write_canonical(X).
ERROR: Syntax error: Operator priority clash
ERROR: X=2@3#
ERROR: ** here **
ERROR: 5#7, write_canonical(X) . 
+5

All Articles