Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!titcca!kddlab!icot32!icot21!chik From: chik@icot.or.jp (Chikayama Takashi) Newsgroups: comp.lang.prolog Subject: Re: co-routining Message-ID: Date: 17 Dec 90 10:41:10 GMT References: Sender: chik@icot32.icot.or.jp Reply-To: chikayama@icot.or.jp Distribution: comp Organization: Institute for New Generation Computer Technology, Tokyo, Japan. Lines: 37 In-reply-to: mark@adler.philosophie.uni-stuttgart.de's message of 7 Dec 90 12:07:58 GMT In article mark@adler.philosophie.uni-stuttgart.de (Mark Johnson) writes: * 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 What's wrong with "freeze"ing a goal which, in addition to calling the main "Goal", will traverse the data structure the variable is instantiated to, hooking up the same goal to all the variables in the structure on its way? For example: delay(Term, Goal) :- freeze(Term, (Goal, traverse(Term, Goal))). traverse(X, Goal) :- var(X), !, freeze(X, Goal). traverse(X, Goal) :- functor(X, _, N), traverse_args(N, X, Goal). traverse_args(0, _, _) :- !. traverse_args(N, X, Goal) :- arg(N, X, Xn), traverse(Xn, Goal), N1 is N-1, traverse_args(N1, X, Goal). which will execute as: | ?- delay(X, write(X)), X = f(Y,Z), Y = [a], Z = b. f(_92,_108)f([a],_343)f([a],b) This calls "write" three times and I guess that's exactly what you want. Or do you want something completely different? Takashi Chikayama ICOT