From a-doug@microsoft.com  Wed Aug  9 23:00:22 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 XAA01603
	for <prolog@swi.psy.uva.nl>; Wed, 9 Aug 2000 23:00:21 +0200 (MET DST)
Received: from 157.54.9.100 by mail3.microsoft.com (InterScan E-Mail VirusWall NT); Wed, 09 Aug 2000 13:59:10 -0700 (Pacific Daylight Time)
Received: by INET-IMC-03 with Internet Mail Service (5.5.2651.58)
	id <Q2QX1DZH>; Wed, 9 Aug 2000 13:58:41 -0700
Message-ID: <E713F2760348D211A9B600805F6FA1AB09509A8E@RED-MSG-09.itg-messaging.redmond.corp.microsoft.com>
From: "Douglas Miles (Volt Computer)" <a-doug@microsoft.com>
To: "'Jan Wielemaker'" <jan@swi.psy.uva.nl>,
        "'prolog@swi.psy.uva.nl'"
	 <prolog@swi.psy.uva.nl>
Subject: RE: Predicate Determining the  port in which was called.
Date: Wed, 9 Aug 2000 13:59:31 -0700 
X-Mailer: Internet Mail Service (5.5.2651.58)

Yes your answer is definately 90% of what I am looking to do.

Since this in my case is

wrap(G) :-
	write('%(call) creating side effects'),nl,
	G,
	(  write('%(exit) comitting side effects '),nl
	;  write('%(redo) me doing nothing '),nl, fail
	).
wrap(_) :-
	write('%(fail) undoing side effects'),nl,
	fail.


?- wrap(true).
%(call) creating side effects
%(exit) comitting side effects

?- wrap(fail).
%(call) creating side effects
%(fail) undoing side effects


I do like this alot.


Where i am having the difficulties is on what is happening on eighter side
of the  ..,wrap(G),.. 
as you mentioned the losing of the choice point information.  

In my case, i Always expect to succeed G.. the like in this case:

test:- member(X,[1,2,3]),wrap(true),X=3. 

or

test:- member(X,[1,2,3]),
	(
	write('%(call)'),write('calling(G)'),(write('%(exit)');
write('%(redo)'),fail)
	;
	write('%(fail)'),fail
	),
	X=3.

I guess i am wanting to find out what happens after G  .. ie (X=3).


when you convert C-ified member/2 or append/3 for exampl2 (done a while ago)
You had to in some way let member and append know if this was the 1st,the
2nd etc iterations.

Its that part that is what i am trying to understand how to do.

Thank you in advance again,
	Douglas.



-----Original Message-----
From: Jan Wielemaker [mailto:jan@swi.psy.uva.nl]
Sent: Wednesday, August 09, 2000 12:49 PM
To: Douglas Miles (Volt Computer); 'prolog@swi.psy.uva.nl'
Subject: RE: Predicate Determining the port in which was called.


> 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

