Path: utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sol.ctr.columbia.edu!ira.uka.de!rusux1!mark From: mark@adler.philosophie.uni-stuttgart.de (Mark Johnson) Newsgroups: comp.lang.prolog Subject: Re: co-routining Message-ID: Date: 7 Dec 90 12:07:58 GMT References: Sender: zrf80385@rusux1.rus.uni-stuttgart.de Distribution: comp Organization: IMS, University of Stuttgart Lines: 30 In-reply-to: ted@nmsu.edu's message of 6 Dec 90 21:55:17 GMT /* Here's a utility predicate freeze/3 for prologs like SICSTUS and BNR * which have freeze/2. It uses a ``shared variable'' which is bound * when one of the frozen goals is run. It's easy to generalize this * to arrange for Goal to be called once whenever *any* variable appearing * in a term (or list) is bound. * * But what I don't know how to do is the following: define a predicate * delay(Term, Goal) which calls Goal when Term is further instantiated, * possibly by unifying distinct variables occuring in Term. * Any ideas? * * Mark Johnson */ freeze(X, Y, Goal) :- % Delay Goal until either X or Y is bound freeze(X, freeze_helper(SharedVar, Goal)), freeze(Y, freeze_helper(SharedVar, Goal)). freeze_helper(SharedVar, _) :- % If SharedVar is bound nonvar(SharedVar), % then the frozen goal !. % has already been run. freeze_helper(done, Goal) :- % Bind SharedVar call(Goal). % and call Goal. test :- freeze(X, Y, write('Frozen goal activated')), X = a, Y = b.