这个序言程序是尾递归的吗?
Is this prolog program in tail recursive?
请问这个程序是不是尾递归的,如果不是的话,如何让它成为尾递归?
euclidsqr([], [], 0).
euclidsqr([X|Xs], [Y|Ys], ED) :-
euclidsqr(Xs, Ys, ED1),
ED is ED1 + (X-Y)*(X-Y).
这里是对应的尾递归版本:
euclidsqr(Xs, Ys, ED) :-
euclidsqr(Xs, Ys, 0, ED).
euclidsqr([], [], ED,ED).
euclidsqr([X|Xs], [Y|Ys], ED0,ED) :-
ED1 is ED0 + (X-Y)*(X-Y),
euclidsqr(Xs, Ys, ED1,ED).
请问这个程序是不是尾递归的,如果不是的话,如何让它成为尾递归?
euclidsqr([], [], 0).
euclidsqr([X|Xs], [Y|Ys], ED) :-
euclidsqr(Xs, Ys, ED1),
ED is ED1 + (X-Y)*(X-Y).
这里是对应的尾递归版本:
euclidsqr(Xs, Ys, ED) :-
euclidsqr(Xs, Ys, 0, ED).
euclidsqr([], [], ED,ED).
euclidsqr([X|Xs], [Y|Ys], ED0,ED) :-
ED1 is ED0 + (X-Y)*(X-Y),
euclidsqr(Xs, Ys, ED1,ED).