Reputation: 43662
I expect the following code to print out [9 4], but this isn't working
:- op(20,xfx,i).
i(X,Y, Z) :-
Z=[X,Y].
main:-
RESULT is 9 i 4, write(RESULT).
Where am I getting wrong?
Upvotes: 1
Views: 448
Reputation: 5615
this works
:- op(800,xfx,i).
R is A i B :-
i(A, B, R).
i(X,Y, Z) :-
Z=[X,Y].
main:-
RESULT is 9 i 4, write(RESULT).
Upvotes: 2
Reputation: 5858
an operator is basically syntactic sugar; instead of writing +(1,2)
we simply write 1+2
.
therefore, 9 i 4
is equivalent to i(9,4)
now, +/2 is not only an operator but also an arithmetic function
note that the result should be a number so you cannot use it to return a list (and cannot use is/2 either)
Upvotes: 3