I am new to Prolog and I’m trying to to create function that will simply remove all instances of an element from a list. The following code is what I have so far:
remove([H|T], E, L2) :- (\+ ([H|T] == []) ->
(H == E
-> remove(T, E, L2)
; append(L2, H, L2), remove(T, E, L2)
)
; append(L2, [])
).
When I run this code on:
remove([1,2,3,4,5], 3, L2).
i get an error:
ERROR: Out of global stack
Could someone point me to why I am getting this problem?
This statement
can never be true because an empty list can never be identical to a list that contains at least one element.