General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Solution

%% Case 1: the input list is empty. 
%% So, the output list should be empty as well.
add_one([],[]).

%% Case 2: the input list is not empty.
%% The head of the output list is obtained by adding 1 to the head of
%% the input list. The tails of the input and the output lists are
%% again lists, and the ouput tail is the list that is obtained from
%% adding 1 to each element of the input tail. That is,
%% add_one(InTail,OutTail) should be true.
add_one([Head|Tail],[OutHead|OutTail]) :-
                         OutHead is Head + 1,
                         add_one(Tail,OutTail).
    

Back to the exercise.