Reputation: 37
I want to add [Startline, Assumption, assumption] to the beginning of list CheckedProof (without creating a new list). Why doesn't this first code snippet give the same result for CheckedProof as the one where I just use append? Is it possible to yield the same result by just using append?
updateList([Element|List1], Element).
updateList(List1, Element):- !,
updateList([Element|List1], Element),!.
updateList(CheckedProof, [Startline, Assumption, assumption]).
append(CheckedProof, [], TemporaryCheckedProof)
append([[Startline, Assumption, assumption]], [TemporaryCheckedProof], CheckedProof).
Upvotes: 0
Views: 52
Reputation: 2422
A Prolog list is by definition a compound term with two arguments. The first argument is the first element of the list, and the second argument is the rest of the list.
Prolog provides the notation List = [H|T]
where you have a list List
that has a first element H
and the rest of the list in T
.
In other words, you don't have to do anything special to add an element at the front of an existing list. Here:
?- Old = [a,b,c], New = [hello|Old].
Old = [a, b, c],
New = [hello, a, b, c].
Not sure what you are doing in your updateList predicate but it seems unnecessary.
Upvotes: 1