Lets say that I would like to construct a list (L2) by appending elements of another list (L) one by one. The result should be exactly the same as the input. This task is silly, but it'll help me understand how to recurse through a list and remove certain elements.
I have put together the following code:
create(L, L2) :- (\+ (L == []) -> L=[H|T], append([H], create(T, L2), L2);[]).
calling it by
create([1,2,3,4], L2)
returns
L2 = [1|create([2,3,4], **)\.
which is not a desired result.