Определение предиката
bagof(E, Z, S) if Z, take_temp_list(S), bagof_servise(E,S), fail.
bagof(_, _, S) if bagof_get(S), retract(temp_list(S)), !.
bagof_get(S) if temp_list(S).
bagof_servise(E,S) if member(E,S), assert(temp_list(S)).
bagof_servise(E,S) if not(member(E,S)), assert(temp_list([E|S])).
take_temp_list([ ]) if not(temp_list(_)), !.
take_temp_list(List) if retract(temp_list(List)), !. |