~/ learn/ comp-456/ cards/ List processing: [H|T], member, append, and recursion over lists
1 of 6

Type member/2 and append/3

Type member/2 and append/3

Answer

member(X, [X | _]). member(X, [_ | T]) :- member(X, T). append([], B, B). append([H | T], B, [H | R]) :- append(T, B, R).

member: X is in the list if it is the head (clause 1) OR a member of the tail (clause 2). append: the base case joins [] to B giving B; the recursive clause carries the head H across and recurses on the tail. The underscore `_` is the anonymous variable (a value we do not need to name).

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/d4e4aa5a-90a5-44fd-8ebf-a5e6ffcddc51/flashcard utf-8 LF