:-table dfs/2.
:-eager_consume dfs/2.
dfs(State,Plan):-
is_final_state(State),!,
Plan=[].
dfs(State,[Move|Plan]):-
select_move(State,Move),
update(State,State1),
dfs(State1,Plan).
This program implements the depth-first search algorithm over a state space. It terminates once a plan is found. Without the eager_consume declaration, however, the program would explore all the state space and would never stop if there are infinite number of plans.