I need to add elements in an empty list in prolog but I am getting into an infinite loop. This is my code:
dot_product([],[],0).
dot_product([M|Ms],[N|Ns],Sum) :-
dot_product(Ms,Ns,S),
Sum is S+M*N.
add_tail([],X,[X]).
add_tail([H|T],X,[H|L]):-
add_tail(T,X,L).
row([],[],[]).
row(RI,[],[]).
row(RI,[Y|O],R) :-
dot_product(RI,Y,R1),
add_tail([],R1,R),
row(RI,O,R).
Example input:
?-row([1,2],[[1,2],[3,4]],R).
Expected output:
R=[5,11]
but instead it goes into an infinite loop.