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

From: "Richard A. O'Keefe" <[email-masked]>
Date: Thu, 10 Aug 2000 12:31:30 +1200 (NZST)

"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.