In order to make Prolog predicates callable from C, users must to replace the main.c file in the emulator with a new file that starts the users' own application. The following function must be executed before any call to Prolog predicates is executed:
initialize_bprolog(int argc, char *argv[])
In addition, the environment variable BPDIR must correctly be set to the home directory in which B-Prolog was installed. The function initialize_bprolog() allocates all of the stacks that are used in B-Prolog, initializes them, and loads the bytecode file bp.out into the program area. BP_ERROR is returned if the system cannot be initialized.
A query can be a string or a Prolog term. A query can return a single solution, or it can return multiple solutions.
- int bp_call_string(char *goal):
This function executes the Prolog call, as represented by the string goal. The return value is BP_TRUE if the call succeeds, BP_FALSE if the call fails, and BP_ERROR if an exception occurs. Examples:
bp_call_string("load(myprog)")
bp_call_string("X is 1+1")
bp_call_string("p(X,Y),q(Y,Z)")
- bp_call_term(TERM goal):
This function is similar to bp_call_string, except that it executes the Prolog call, as represented by the term goal. While bp_call_string cannot return any bindings for variables, this function can return results through the Prolog variables in goal. Example:
TERM call = bp_build_structure("p",2);
bp_call_term(call);
- bp_mount_query_string(char *goal):
Mounts goal as the next Prolog goal to be executed.
- bp_mount_query_string(TERM goal):
Mounts goal as the next Prolog goal to be executed.
- bp_next_solution():
Retrieves the next solution of the current goal. If no goal is mounted before this function, then the exception illegal_predicate will be raised, and BP_ERROR will be returned as the result. If no further solution is available, the function returns BP_FALSE. Otherwise, the next solution is found.
Subsections
Neng-Fa Zhou
2013-01-25