Subject: Re: [SWIPL] exceptions in PL_call_predicate()

From: Jan Wielemaker <[email-masked]>
Date: Sat, 17 Feb 2001 11:43:48 +0100

> I have a foreign predicate which calls PL_call_predicate(): if I find
> that this call has raised an exception, I want to just fail out of the
> foreign predicate and let Prolog handle the exception.
> 
> Is this safe?  good practice?

There is an option for this:

    PL_Q_PASS_EXCEPTION
         As PL_Q_CATCH_EXCEPTION,  but do  not invalidate the  exception-
         term  while   calling  PL_close_query().      This  option   is
         experimental.

This flag is documented with PL_open_query().  The flags of
PL_call_predicate are the same.  It isn't very experimental any more.

Actually PL_call_predicate is defined as:

int
PL_call_predicate(Module ctx, int flags, predicate_t pred, term_t h0)
{ int rval;

  qid_t qid = PL_open_query(ctx, flags, pred, h0);
  rval = PL_next_solution(qid);
  PL_cut_query(qid);

  return rval;
}

and PL_cut_query() doesn't touch the exception term, so it is safe without
PL_Q_PASS_EXCEPTION as well.  Nevertheless, adding this flag makes it
clear what you are doing and thus more likely it will not only work
today but also next year.

	--- Jan