Type Definition clingo_sys::clingo_ground_callback_t
[−]
[src]
type clingo_ground_callback_t = Option<unsafe extern "C" fn(_: *const clingo_location_t, _: *const c_char, _: *const clingo_symbol_t, _: usize, _: *mut c_void, _: clingo_symbol_callback_t, _: *mut c_void) -> bool>;
Callback function to implement external functions.
If an external function of form \@name(parameters) occurs in a logic program, then this function is called with its location, name, parameters, and a callback to inject symbols as arguments. The callback can be called multiple times; all symbols passed are injected.
If a (non-recoverable) clingo API function fails in this callback, for example, the symbol callback, the callback must return false. In case of errors not related to clingo, this function can set error ::clingo_error_unknown and return false to stop grounding with an error.
Parameters:
location
location from which the external function was calledname
name of the called external functionarguments
arguments of the called external functionarguments_size
number of argumentsdata
user data of the callbacksymbol_callback
function to inject symbolssymbol_callback_data
user data for the symbol callback (must be passed untouched)
Returns whether the call was successful @see clingo_control_ground()
The following example implements the external function \@f() returning 42. ~~~~~~~~~~~~~~~{.c} bool ground_callback(clingo_location_t const *location, char const *name, clingo_symbol_t const *arguments, size_t arguments_size, void *data, clingo_symbol_callback_t symbol_callback, void *symbol_callback_data) { if (strcmp(name, "f") == 0 && arguments_size == 0) { clingo_symbol_t sym; clingo_symbol_create_number(42, &sym); return symbol_callback(&sym, 1, symbol_callback_data); } clingo_set_error(clingo_error_runtime, "function not found"); return false; } ~~~~~~~~~~~~~~~