sasagawa888 / nprolog

interpreter and compiler to be compatible with ARITY/PROLOG(MS-DOS)
Other
76 stars 5 forks source link

call/4 #68

Closed sasagawa888 closed 2 years ago

sasagawa888 commented 2 years ago

It is convenient to have call/4

sasagawa888 commented 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 ?-