Studying Prolog, I am trying to solve the following problem using batteries:
Write the predicate addone2 /, whose first argument is a list of integers, and the second argument is a list of integers obtained by adding 1 to each integer in the first list. For example, request
addone([1,2,7,2],X).
should give
X = [2,3,8,3].
I created the following code:
addone([], _).
addone([E|Tail], [R|Rs]) :-
NewE is E+1,
append([R|Rs], [NewE], NewRs),
addone(Tail, NewRs).
But it does not work. Can someone tell me why? So how can I use batteries in Prolog?
Thank!
source
share