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

From: "Douglas Miles (Volt Computer)" <[email-masked]>
Date: Wed, 9 Aug 2000 13:59:31 -0700

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:[email-masked]]
Sent: Wednesday, August 09, 2000 12:49 PM
To: Douglas Miles (Volt Computer); [email-masked]'
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