Closed sasagawa888 closed 2 years ago
It's possible to implement fold/3 with call/1
e.g.
%fold(_, [E], E). %fold(Pred, [X, Y | Z], Rez) :- % call(Pred, X, Y, R1), % fold(Pred, [R1 | Z], Rez).
fold(_, [E], E). fold(Pred, [X, Y | Z], Rez) :- P2 =.. [Pred,X,Y,R1], call(P2), fold(Pred, [R1 | Z], Rez).
plus(X,Y,A) :- A is X+Y.
?- fold(plus,[1,2,3],X). X = 6 . yes ?-
It is convenient to have call/4