From jan@swi.psy.uva.nl  Wed Aug  9 21:48:43 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id VAA29178;
	Wed, 9 Aug 2000 21:48:43 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id VAA10008;
	Wed, 9 Aug 2000 21:48:50 +0200
Date: Wed, 9 Aug 2000 21:48:50 +0200
Message-Id: <200008091948.VAA10008@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: RE: Predicate Determining the  port in which was called.
To: "Douglas Miles (Volt Computer)" <a-doug@microsoft.com>,
        "'prolog@swi.psy.uva.nl'" <prolog@swi.psy.uva.nl>
In-Reply-To: Volt Computer's message of Wed, 9 Aug 2000 11:23:39 -0700 
Phone: +31 - 20 - 525 6121

> Corrections: (actually i am not sure if this is correct eighter)
> 
> 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.

Note really sure this is what you mean  but here is a try:

In principle you can wrap a goal into something like:

wrap(G) :-
	at_call,
	G,
	(  at_exit
	;  at_redo, fail
	).
wrap(_) :-
	at_fail,
	fail.

where you insert code at the at_* places to the thing you need done there.
Note however that this is not perfect.  First of all, you need to add some
more tricks to get exceptions working properly (but this can be done) and
second, if the choicepoint is cut you will not be informed:

test :-
	wrap(hello),
	!.

You can deal with this case using foreign code as discussed on the
mailinglist before.

	--- Jan

