🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1650

Re: co-routining

#1650
From: Mark Johnson
Date: Fri, 07 Dec 1990 12:07
30 lines
1688 bytes
/* 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.
Technical Details
Message-ID: <MARK.90Dec7130758@adler.philosophie.uni-stuttgart.de>
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sol.ctr.columbia.edu!ira.uka.de!rusux1!mark
References: <TED.90Dec6145517@aiaia.nmsu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <MARK.90Dec7130758@adler.philosophie.uni-stuttgart.de>
Date: 7 Dec 90 12:07:58 GMT
References: <TED.90Dec6145517@aiaia.nmsu.edu>
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