Thanks Jose. I've decided to reduce my C usage to only what is necessary and use Prolog whereever possible.
But, I really am trying to interface Ciao to a system that has a C driver library. The system is written in C++ and has a C++ driver library that is more efficient and otherwise better. I have two more questions:
1) Can foreign C predicates be in a library file or do they have to be compiled by ciaoc along with the prolog code? 2) Has anyone successfully used C++ for foreign code with ciao and what did they do to make it work?
Thanks again, John
Jose Morales-3 wrote:
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,
-- Jose
Ciao-users mailing list Ciao-users(a)clip.dia.fi.upm.es http://clip.dia.fi.upm.es/cgi-bin/mailman/listinfo/ciao-users