Suppose I would like to build a list (L2) by adding the elements of another list (L) one by one. The result should be exactly the same as the input. This task is stupid, but it will help me understand how to go through the list and remove certain items.
I have compiled the following code:
create(L, L2) :- (\+ (L == []) -> L=[H|T], append([H], create(T, L2), L2);[]).
calling him
create([1,2,3,4], L2)
returns
L2 = [1|create([2,3,4], **)\.
which is not the desired result.
source share