Re: Eclipse External Language Interface (C)

From: Warwick Harvey <wh_at_icparc.ic.ac.uk>
Date: Wed 10 Jan 2001 05:53:16 PM GMT
Message-ID: <3A5CA18C.4FC5FE71@icparc.ic.ac.uk>
gemichael@cytanet.com.cy wrote:
> The exact backtracking I am trying to achieve is as follows:
> 
> "p_run/2" is an external C predicate
> "run/1" is the corresponding Eclipse predicate
> run(x), succeeds if x is grounded and 0<x<k, where k is finite but
> unknown to the eclipse program.
> 
> The program is:
> 
> start:- ...predicates...., prog, ..... predicates2
> prog:- number(X), run(X), ....predicates1
> number(1).
> number(X):- number(Y), X is Y+1.
> 
> The goal here is to call "run" (and thus the external predicate),
> passing all the integers, starting from 1. "run" will succeed for
> 1,2,...k-1 and fail for k, k+1, and so forth. The computation can also
> fail during the execution of predicates1 or predicates2. I would like
> to have the following conditions on the execution:
> 
> (1.) if run(x) succeeds and predicates1 and predicates2 succeed, the
> computation continues  normally.
> (2.) if run(x) succeeds, but predicates1 or predicates2 fail, then,
> "run" should be called with a new value for x and (1.)
> (3.) if run(x) fails for some value of x (then by definition of "run"
> it will fail for all the following values of x), then the computation
> of prog should fail.
> 
> Note that predicates1 and predicates2 succeed/fail according to side
> effects (file data) of the external predicate.

Hi Michael,

I suggest you do something like this:

prog(X) :-
	number(X),
	( run(X) ->
		... predicates1
	;
		!,
		fail
	).

What this does is first generate a number to test.  If run(X) succeeds,
it goes on to call the other predicates as normal.  If those other
predicates fail, it backtracks to the call to number(X) and tries a
different value of X.  The first time run(X) fails, however, the
choicepoint in number(X) is pruned (so no more options are tried), and
the predicate fails.

Hope that helps.

Cheers,
Warwick
Received on Wed Jan 10 17:53:17 2001

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:08:03 PM GMT GMT