I need to write a recursion in prolog, which adds elements of two lists. Let's say we have a list, A = [a,b,c], and B = [d,e,f] and the final list, R, should look like this: R = [a+d, b+e, c+f].
I came up only with this:
xxx([a], [b], [a+b]).
xxx([H1|T1], [H2|T2], W) :- xxx(T1, T2, W), .(H1+H2, W).
But it gives me uncaught exception: error(syntax_error('user_input:5 (char:15) expression or ] expected in list'),read_term/3). I also tried this:
xxx([a], [b], [a+b]).
xxx([H1|T1], [H2|T2], W) :- xxx(T1, T2, W), append(H1+H2, W, []).
With no success: uncaught exception: error(syntax_error('user_input:4 (char:16) expression or ] expected in list'),read_term/3)
Im using Gnu prolog (gprolog)
.for building lists is usually hidden; you need to do some "trick" to be able to use it. This is probably what is giving the syntax error.