Subject: Re: [Fwd: Non-redundant wrappers?]

From: Jan Wielemaker <[email-masked]>
Date: Thu, 18 May 2000 16:16:42 +0200

> > 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