I want to write a rule to exhaust the database and fill a list with some items but the prolog interpreter always returns with: Out of global stack.
fill(SomeParams, List) :- append(List, [NewItem], List), fail.
Is there a way to extend a list without doing unification?
Your
append
can't work because it states thatList
is the result of appending[NewItem]
toList
, soList
is supposed to be two things at once. Remember, variables in Prolog are logical variables that can never be changed, once they are bound.You can use
findall/3
, as CapelliC said, or if you want more control, you can do something like this:Then