Native C API - Execution Contexts

Enumerations

enum  p_consult_option { P_CONSULT_DEFAULT = 0, P_CONSULT_ONCE = 1 }
enum  p_goal_result { P_RESULT_FAIL = 0, P_RESULT_TRUE = 1, P_RESULT_ERROR = 2, P_RESULT_HALT = 3 }

Functions

p_context * p_context_create (void)
 Creates and returns a new execution context.
void p_context_free (p_context *context)
 Frees an execution context.
void * p_context_mark_trail (p_context *context)
 Marks the current position in the backtrack trail in context and returns a marker pointer.
void p_context_backtrack_trail (p_context *context, void *marker)
 Backtracks the trail in context, undoing variable bindings until marker is reached.
int p_context_consult_file (p_context *context, const char *filename, p_consult_option option)
 Loads and consults the contents of filename as predicates and directives to be executed within context.
int p_context_consult_string (p_context *context, const char *str)
 Loads and consults the contents of str as predicates and directives to be executed within context.
p_goal_result p_context_execute_goal (p_context *context, p_term *goal, p_term **error)
 Executes goal against the current database state of context.
p_goal_result p_context_reexecute_goal (p_context *context, p_term **error)
 Re-executes the current goal on context by forcing a back-track to find a new solution.
void p_context_abandon_goal (p_context *context)
 Abandons the current goal on context.
double p_context_fuzzy_confidence (p_context *context)
 Returns the fuzzy confidence factor for the last top-level solution that was returned on context.
void p_context_set_fuzzy_confidence (p_context *context, double value)
 Sets the fuzzy confidence factor for context to value.
p_goal_result p_context_call_once (p_context *context, p_term *goal, p_term **error)
 Calls goal once on context. Returns a result code and an optional error term in error.
int p_context_is_debug (p_context *context)
 Returns the current debug state for context.
void p_context_set_debug (p_context *context, int debug)
 Sets the current debug state for context.
void p_context_add_import_path (p_context *context, const char *path)
 Adds path to context as a directory to search for source files imported by import/1.
void p_context_add_library_path (p_context *context, const char *path)
 Adds path to context as a directory to search for library files loaded by load_library/1.

Enumeration Type Documentation

This enum defines options for p_context_consult_file().

Enumerator:
P_CONSULT_DEFAULT 

Default options. The file will be loaded again every time it is consulted. This is used by the consult/1 directive.

P_CONSULT_ONCE 

The file will only be consulted once. Subsequent attempts to consult the file will quietly succeed. This is used by the import/1 directive.

Definition at line 36 of file context.h.

This enum defines the result from a goal or builtin predicate.

See also:
p_context_execute_goal()
Enumerator:
P_RESULT_FAIL 

The goal failed and further back-tracking is not possible.

P_RESULT_TRUE 

The goal succeeded and further back-tracking may be possible.

P_RESULT_ERROR 

The goal resulted in a thrown error that has not been caught. Further back-tracking may be possible. The error term should be generated with one of the functions in the Error Creation module.

P_RESULT_HALT 

The goal resulted in execution of a halt/0 or halt/1 subgoal. Execution should wind back to the top-level goal and return control to the caller of p_context_execute_goal().

Definition at line 45 of file context.h.


Function Documentation

void p_context_abandon_goal ( p_context *  context  ) 

Abandons the current goal on context.

All variable bindings that were made as part of the current goal are removed. The context returns to its original conditions, except for any side-effects that were performed by the goal.

See also:
p_context_execute_goal(), p_context_reexecute_goal()

Definition at line 878 of file context.c.

void p_context_add_import_path ( p_context *  context,
const char *  path 
)

Adds path to context as a directory to search for source files imported by import/1.

See also:
p_context_consult_file(), p_context_add_library_path()

Definition at line 1088 of file context.c.

void p_context_add_library_path ( p_context *  context,
const char *  path 
)

Adds path to context as a directory to search for library files loaded by load_library/1.

See also:
p_context_add_library_path()

Definition at line 1100 of file context.c.

void p_context_backtrack_trail ( p_context *  context,
void *  marker 
)

Backtracks the trail in context, undoing variable bindings until marker is reached.

See also:
p_context_mark_trail()

Definition at line 168 of file context.c.

p_goal_result p_context_call_once ( p_context *  context,
p_term *  goal,
p_term **  error 
)

Calls goal once on context. Returns a result code and an optional error term in error.

This function is intended for calling back from a builtin function into the Plang execution engine. Back-tracking of the top level of goal is not supported.

See also:
p_context_execute_goal(), p_context_fuzzy_confidence()

Definition at line 951 of file context.c.

int p_context_consult_file ( p_context *  context,
const char *  filename,
p_consult_option  option 
)

Loads and consults the contents of filename as predicates and directives to be executed within context.

Returns zero if the file was successfully consulted, or an errno code otherwise. EINVAL indicates that the contents of filename could not be completely parsed. Other errno codes indicate errors in opening or reading from filename.

The special filename - can be used to read from standard input.

If option is P_CONSULT_ONCE and filename has already been loaded into context previously, then this function does nothing and returns zero.

See also:
p_context_consult_string(), p_context_add_import_path()

Definition at line 350 of file context.c.

int p_context_consult_string ( p_context *  context,
const char *  str 
)

Loads and consults the contents of str as predicates and directives to be executed within context.

Returns zero if the contents of str were successfully consulted, or an errno code otherwise. EINVAL indicates that the contents of str could not be completely parsed.

This function is intended for parsing small snippets of source code that have been embedded in a larger native application. Use p_context_consult_file() for parsing external files.

See also:
p_context_consult_file()

Definition at line 406 of file context.c.

p_context* p_context_create ( void   ) 

Creates and returns a new execution context.

See also:
p_context_free()

Definition at line 49 of file context.c.

p_goal_result p_context_execute_goal ( p_context *  context,
p_term *  goal,
p_term **  error 
)

Executes goal against the current database state of context.

Returns a goal status of P_RESULT_FAIL, P_RESULT_TRUE, P_RESULT_ERROR, or P_RESULT_HALT. The previous goal, if any, will be abandoned before execution of goal starts.

If error is not null, then it will be set to the error term for P_RESULT_ERROR.

If the return value is P_RESULT_HALT, then error will be set to an integer term corresponding to the requested exit value.

See also:
p_context_reexecute_goal(), p_context_abandon_goal(), p_context_fuzzy, confidence(), Plang execution model

Definition at line 797 of file context.c.

void p_context_free ( p_context *  context  ) 

Frees an execution context.

See also:
p_context_create()

Definition at line 94 of file context.c.

double p_context_fuzzy_confidence ( p_context *  context  ) 

Returns the fuzzy confidence factor for the last top-level solution that was returned on context.

The confidence factor is between 0 and 1 and indicates how confident the application is of the solution when it involves fuzzy reasoning. For example, 0.8 indicates that the application is 80% confident about the returned solution.

The value will be 0 if a top-level failure or thrown error has occurred. The value will be 1 if a top-level success has occurred with normal confidence. The values will be between 0 and 1 if a top-level success has occurred but the confidence is less than total

See also:
p_context_execute_goal(), p_context_reexecute_goal(), p_context_set_fuzzy_confidence(), Fuzzy logic.

Definition at line 911 of file context.c.

int p_context_is_debug ( p_context *  context  ) 

Returns the current debug state for context.

See also:
p_context_set_debug()

Definition at line 1065 of file context.c.

void* p_context_mark_trail ( p_context *  context  ) 

Marks the current position in the backtrack trail in context and returns a marker pointer.

See also:
p_context_backtrack_trail()

Definition at line 153 of file context.c.

p_goal_result p_context_reexecute_goal ( p_context *  context,
p_term **  error 
)

Re-executes the current goal on context by forcing a back-track to find a new solution.

Returns a goal status of P_RESULT_FAIL, P_RESULT_TRUE, P_RESULT_ERROR, or P_RESULT_HALT reporting the status of the new solution found. If P_RESULT_TRUE is returned, then further solutions are possible.

If error is not null, then it will be set to the error term for P_RESULT_ERROR.

If the return value is P_RESULT_HALT, then error will be set to an integer term corresponding to the requested exit value.

See also:
p_context_execute_goal(), p_context_abandon_goal(), p_context_fuzzy_confidence(), Plang execution model

Definition at line 848 of file context.c.

void p_context_set_debug ( p_context *  context,
int  debug 
)

Sets the current debug state for context.

See also:
p_context_is_debug()

Definition at line 1076 of file context.c.

void p_context_set_fuzzy_confidence ( p_context *  context,
double  value 
)

Sets the fuzzy confidence factor for context to value.

The confidence factor is between 0 and 1 and indicates how confident the application is of the solution when it involves fuzzy reasoning.

The value will be clamped to between 0.00001 and 1. It is not possible to set value to 0, as that value should be indicated by P_RESULT_FAIL instead.

See also:
p_context_fuzzy_confidence(), Fuzzy logic.

Definition at line 930 of file context.c.


Generated on 26 May 2011 for plang by  doxygen 1.6.1