Trait clingo::ExternalFunctionHandler
[−]
[src]
pub trait ExternalFunctionHandler { fn on_external_function(
&mut self,
location: &Location,
name: &str,
arguments: &[Symbol]
) -> Result<Vec<Symbol>, ClingoError>; }
Required Methods
fn on_external_function(
&mut self,
location: &Location,
name: &str,
arguments: &[Symbol]
) -> Result<Vec<Symbol>, ClingoError>
&mut self,
location: &Location,
name: &str,
arguments: &[Symbol]
) -> Result<Vec<Symbol>, ClingoError>
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 ErrorType::Unknown
and return false to stop grounding with an error.
Arguments
location
- location from which the external function was calledname
- name of the called external functionarguments
- arguments of the called external function
Returns a vector of symbols
See: Control::ground_with_event_handler()
The following example implements the external function @f()
returning 42.
fn on_external_function( &mut self, _location: &Location, name: &str, arguments: &[Symbol], ) -> Result<Vec<Symbol>,ClingoError> { if name == "f" && arguments.len() == 0 { let symbol = Symbol::create_number(42); Ok(vec![symbol]) } else { Err(ClingoError { type_: ErrorType::Runtime, msg: "function not found", }) } }