Subject: RE: Predicate Determining the port in which was called.

From: "Douglas Miles (Volt Computer)" <[email-masked]>
Date: Thu, 10 Aug 2000 11:37:53 -0700

"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:[email-masked]]
Sent: Wednesday, August 09, 2000 5:32 PM
To: Douglas Miles (Volt Computer); [email-masked]
Subject: RE: Predicate Determining the port in which was called.

"Douglas Miles (Volt Computer)" <[email-masked]> 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 [email-masked] 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/