Example



next up previous WS Presentations Main Page
Next: Example Up: Document: ciao Previous: Example

Example

:- module(prod_cons,_,ciao(h)).

main :- consumer(L)& , producer(10,L).

producer(0,T) :- !, T = [].
producer(N,T) :- N > 0,
        T = [N|Ns],
        N1 is N-1,
        report(N,produced),
        producer(N1,Ns).

consumer(T) :-
        wait(T),
        consumer_body(T).

consumer_body([]).
consumer_body([H|T]) :-
        report(H,consumed),
        consumer(T).

report(H,PC) :-
        worker(W),
        format('Worker ~d ~w ~d~n', [W,PC,H]),
        flush_output(user_output).



Thu Jan 18 11:29:48 MET 1996 <herme@fi.upm.es>-<webmaster@clip.dia.fi.upm.es>