From ok@atlas.otago.ac.nz  Thu Aug 10 02:31:32 2000
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id CAA07281
	for <prolog@swi.psy.uva.nl>; Thu, 10 Aug 2000 02:31:30 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id MAA03688;
	Thu, 10 Aug 2000 12:31:30 +1200 (NZST)
Date: Thu, 10 Aug 2000 12:31:30 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200008100031.MAA03688@atlas.otago.ac.nz>
To: a-doug@microsoft.com, 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.

