🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1670

Re: co-routining

#1670
From: Chikayama Takashi
Date: Mon, 17 Dec 1990 10:41
37 lines
1910 bytes
In article <MARK.90Dec7130758@adler.philosophie.uni-stuttgart.de> 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
Technical Details
Message-ID: <CHIK.90Dec17194110@icot21.icot.or.jp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!titcca!kddlab!icot32!icot21!chik
References: <TED.90Dec6145517@aiaia.nmsu.edu> <MARK.90Dec7130758@adler.philosophie.uni-stuttgart.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <CHIK.90Dec17194110@icot21.icot.or.jp>
Date: 17 Dec 90 10:41:10 GMT
References: <TED.90Dec6145517@aiaia.nmsu.edu>
 <MARK.90Dec7130758@adler.philosophie.uni-stuttgart.de>
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