Re: Question about demons

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Wed 19 Jan 2005 02:07:46 PM GMT
Message-ID: <41EE69B2.5000209@icparc.ic.ac.uk>
Ulrich Scholz wrote:

 > The user manual suggests the following method to initiate demons:
 >
 > % A demon that wakes whenever X becomes more constrained
 > report(X) :-
 >       suspend(report(X, Susp), 1, X->constrained, Susp).
 >
 > :- demon(report/2).
 > report(X, _Susp) :-
 >       ( var(X) ->
 >           writeln(constrained(X)) % implicitly re-suspend
 > ;
 >           writeln(instantiated(X)),
 >           kill_suspension(Susp) % remove from the resolvent
 > ).
 >
 >
 > Is there a way to communicate some information to report/2 at the time of
 > initiation, e.g., some string or a handle of a shelf?


Just add an argument to report/1 and report/2:

report(X, Handle) :-
     suspend(report(X, Handle, Susp), 1, X->constrained, Susp).

:- demon(report/3).
report(X, Handle, _Susp) :-
     ( var(X) ->
         <store information in handle>
     ;
         <store information in handle>
         kill_suspension(Susp)
     ).

?-    <create X>,
     <create Handle>,
     report(X, Handle),
     <computation with X>,
     <process information collected in Handle>.



-- 
  Joachim Schimpf              /             phone: +44 20 7594 8187
  IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
  Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Wed Jan 19 14:09:19 2005

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:33 PM GMT GMT