SWI-Prolog 9.2.6 Reference Manual

# 12 Foreign Language Interface

SWI-Prolog offers a powerful interface to C Kernighan & Ritchie, 1978. The main design objectives of the foreign language interface are flexibility and performance. A foreign predicate is a C function that has the same number of arguments as the predicate represented. C functions are provided to analyse the passed terms, convert them to basic C types as well as to instantiate arguments using unification. Non-deterministic foreign predicates are supported, providing the foreign function with a handle to control backtracking.

C can call Prolog predicates, providing both a query interface and an interface to extract multiple solutions from a non-deterministic Prolog predicate. There is no limit to the nesting of Prolog calling C, calling Prolog, etc. It is also possible to write the‘main’in C and use Prolog as an embedded logical engine.

## Section Index