If I have a list in Prolog such as X = [1, 2, 3, 4], how do I add the element 5 to the end of the list to have X = [1, 2, 3, 4, 5]?
The append function needs two lists
Since Prolog has append which only accepts lists, why don't we use it to insert our element in one of the lists. i.e.
% E = element, L = list, R = result % e.g. add_elem_in_list ([1,2,3,4], 5, R). add_elem_in_list(L, E, R) :- append(L, [E], R).