%
% Important note: the following class example is provided "as
% is", for reference purposes, and without any claims of correctness.
%
%

:- use_module(library(ordsets)).

start(1).
edge(1,2).
edge(2,2).
edge(2,3).
edge(3,4).
edge(3,5).


reach_more(R, MoreR) :-
	findall(N,
		(
		 member(Nr, R),
		 edge(Nr, N)
		),
		Delta),
	list_to_ord_set(Delta, DeltaO),
	list_to_ord_set(R, RO),
	ord_union(RO, DeltaO, MoreR).

cr :-
	retractall(reached(_)),
	print('Start!\n'),
	start(S),
	assert(reached([S])),
	compute_fixpoint.

compute_fixpoint :-

	retract(reached(R)),
	format('Reached = ~p\n', [R]),

	print('Step!\n'),
	reach_more(R, MoreR),
	assert(reached(MoreR)),
	( ord_seteq(R, MoreR) ->
	  true
	;
	  compute_fixpoint
	).