From jan@swi.psy.uva.nl  Thu May 18 16:16:21 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 QAA13849;
	Thu, 18 May 2000 16:16:21 +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 QAA08958;
	Thu, 18 May 2000 16:16:42 +0200
Date: Thu, 18 May 2000 16:16:42 +0200
Message-Id: <200005181416.QAA08958@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: [Fwd: Non-redundant wrappers?]
To: Paul Singleton <p.singleton@keele.ac.uk>
In-Reply-To: Paul Singleton's message of Thu, 18 May 2000 14:13:26 +0100
Phone: +31 - 20 - 525 6121
Cc: prolog@gollem.swi.psy.uva.nl

> > call_cleanup() is already provided for foreign code, so in your case, it
> > only implies you can implement it cleanly for both SWI and SICStus (ok,
> > differently, but with tactical abstraction you should be able to share
> > 90% of the code anyway).  I think you can call Prolog from the
> > PL_CUTTED hook of a non-deterministic foreign routine (never tried it
> > though).
> 
> Hmm, do you think I could implement a generic call_cleanup(Goal,CleanupGoal)
> as a foreign function, using your PL_CUTTED feature?  That would be neat...

No.  Thats one step too far.  You cannot write a foreign call_x(Goal)
that treats the non-deterministic behaviour of Goal properly because
you must close open queries before returning from a foreign predicate.

It would be nice to have, but I think hard to implement.  You can
however write a foreign predicate that does non-deterministic
extraction of tuples and nicely cleans up its environment on cutting,
exceptions, failure or deterministic success.  If you write the thing
modular enough, it appears you can do the same in SICStus without too
much duplication.

In other words, if you have a deterministic get-first, get-next and
cleanup you can use SWI-Prolog foreign code to construct a
non-deterministic predicate that is guaranteed to call cleanup.  

	Regards --- Jan

