General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Practice using the cut

Yesterday there was an exercise which introduced the cut. With this exercise you practice to use the cut.

Define a predicate remove(+X,+InList,?OutList) such that OutList is obtained by removing the first occurrence of X from InList. If X does not occur in +InList, just return the list as it is.

Note, that the predicate is supposed to only remove the first occurrence of the specified element. So, you need the cut to stop Prolog from backtracking and deleting later occurrences as well.

Hint

Back to the practical session of day3.