From a-doug@microsoft.com  Thu Aug 10 21:19:17 2000
Received: from mail3.microsoft.com (mail3.microsoft.com [131.107.3.123])
	by swi.psy.uva.nl (8.9.3/8.9.3) with SMTP id VAA04876
	for <prolog@swi.psy.uva.nl>; Thu, 10 Aug 2000 21:19:16 +0200 (MET DST)
Received: from 157.54.9.100 by mail3.microsoft.com (InterScan E-Mail VirusWall NT); Thu, 10 Aug 2000 11:36:53 -0700 (Pacific Daylight Time)
Received: by INET-IMC-03 with Internet Mail Service (5.5.2651.58)
	id <Q2QX281R>; Thu, 10 Aug 2000 11:36:39 -0700
Message-ID: <E713F2760348D211A9B600805F6FA1AB09509A93@RED-MSG-09.itg-messaging.redmond.corp.microsoft.com>
From: "Douglas Miles (Volt Computer)" <a-doug@microsoft.com>
To: "'Richard A. O'Keefe'" <ok@atlas.otago.ac.nz>, prolog@swi.psy.uva.nl
Subject: RE: Predicate Determining the  port in which was called.
Date: Thu, 10 Aug 2000 11:37:53 -0700
X-Mailer: Internet Mail Service (5.5.2651.58)

"the port in which a predicate was called over" was not correct (my subject
line even more incorrect =)
maybe "i want to make the predicate do different things depending on the
port"

With the given program...

	p(Goal) :-
	    (   (write('(call) getting oldest item in que \n'),fail)
	    ;   true
	    ;   (write('(fail) putting back as oldest in que\n'), fail)
	    ),
	    writeq(Goal),nl,Goal,
	    (   (write('(exit)\n'), fail)
	    ;   true
	    ;   (write('(redo) putting that oldest back in as newest\n'),
fail)
	    ). 

-------------------------------------------------------------------
?- p(true).
-------------------------------------------------------------------
(call) getting oldest item in que
true
(exit)
Yes

Comment: Perfect

-------------------------------------------------------------------
?- p(member(X,[1,2,3])),X=3.
-------------------------------------------------------------------
(call) getting oldest item in que
member(_G306, [1, 2, 3])
(exit)
(redo) putting that oldest back in as newest
(exit)
(redo) putting that oldest back in as newest
(exit)
X = 3
Yes

Comment: Close (but one extra iteration)

-------------------------------------------------------------------
?- member(X,[1,2,3]) ,p( write('whee\!\!\!\n') ),X=3.
-------------------------------------------------------------------
(call) getting oldest item in que
write('whee!!!\n')
whee!!!
(exit)
(redo) putting that oldest back in as newest
(fail) putting back as oldest in que
(call) getting oldest item in que
write('whee!!!\n')
whee!!!
(exit)
(redo) putting that oldest back in as newest
(fail) putting back as oldest in que
(call) getting oldest item in que
write('whee!!!\n')
whee!!!
(exit)
X = 3
Yes

Comment: Close (but one extra subiteration)

-------------------------------------------------------------------
?- member(X,[1,2,3]) ,p( write('whee\!\!\!\n') ),fail.
-------------------------------------------------------------------
(call) getting oldest item in que
write('whee!!!\n')
whee!!!
(exit)
(redo) putting that oldest back in as newest
(fail) putting back as oldest in que
(call) getting oldest item in que
write('whee!!!\n')
whee!!!
(exit)
(redo) putting that oldest back in as newest
(fail) putting back as oldest in que
(call) getting oldest item in que
write('whee!!!\n')
whee!!!
(exit)
(redo) putting that oldest back in as newest
(fail) putting back as oldest in que

Comment: Same Issue (but if i was to keep a state arround based on if it was
in/out of the que then i probly wouldnt have an issue)

-------------------------------------------------------------------
What you have gets me very close !

from the trace you can see my goal is to have a way of wrapping Inline
external helper functions.
Like may the way one would for a non-determ stream or writeln that bails out
and never flushes it's buffer except when the goal exits for good (maybe i
am asking too much for p(...) to get informed down the line about an exit)

I guess p(...) only really needs informed on a redo or fail.  
I'll pretend that p(...) is not responsible for the final flushing.

Does what i am doing seem correct, or am I asking do something logicly
impure? 
(thank you if you can Help me modify the above program)


  Thanks in advance,
	Douglas



-----Original Message-----
From: Richard A. O'Keefe [mailto:ok@atlas.otago.ac.nz]
Sent: Wednesday, August 09, 2000 5:32 PM
To: Douglas Miles (Volt Computer); prolog@swi.psy.uva.nl
Subject: RE: Predicate Determining the port in which was called.


"Douglas Miles (Volt Computer)" <a-doug@microsoft.com> wrote:

	I want to write but do not know how is to determine the port in
which a
	predicate was called over:
	
	example:
	
	test:- member(X,[1,2,3]),mypredicate,X=4.
	mypredicate:- port(call),write('% creating side effects'),nl.
	mypredicate:- port(redo),write('% doing nothing'),nl.
	mypredicate:- port(exit),write('% comitting side effects'),nl.
	mypredicate:- port(fail),write('% undoing side effects'),nl.
	
	Code above, i know is not logicaly even close to what it would look
like :)

It doesn't make sense to say "the port in which a predicate was called
over".
Predicates are always called via the call port; that's what the call port
_means_.

For the original DEC-10 Prolog 4-port "Byrd Box" model:

	p(...) :-
	    (   /* Call action, */ fail
	    ;   true
	    ;   /* Fail action, */ fail
	    ),
	    /* normal definition, */
	    (   /* Exit action, */ fail
	    ;   true
	    ;   /* Redo action, */ fail
	    ).

will do the trick.  Beware of exceptions, however.  You may want to
undo some side effect if an exception blasts out of your predicate.


----------------
* To UNSUBSCRIBE, please use the HTML form at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to prolog-request@swi.psy.uva.nl using the Subject:
"unsubscribe"
(without the quotes) and *no* message body.

** An ARCHIVE of this list is maintained at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/

