On Sat, Jan 19, 2013 at 7:35 PM, mcculloch <mccullochj(a)att.net> wrote:
Does anyone know how to make a foreign predicate, written in C, fail or provide backtrack points?
Dear John,
there exists two ways in Ciao to make a foreign predicate:
- low-level user interface (which allows direct access to the underlying virtual machine definitions) - high-level user interface (which uses assertions to map C functions as predicates)
Currently, only the first one allows failure or creation of choicepoints, but we discourage using it, since it is mostly undocumented, error prone, and hard to maintain.
However, you can simulate both failure and choice point creation using a Prolog wrapper. E.g., if check_foo_c/2 is a check written in C which returns '0' or '1' in its second argument, then you can write:
check_foo(X) :- check_foo_c(X, R), R = 1.
which maps the '0' result to a failure. A similar technique can be used to write nondeterministic programs using pieces in C.
If your program can be decomposed in such a way, then this may be a solution. If not, can you provide us at least some pseudo-code? We'll try to find the best solution or implement the missing functionality.
Cheers,