C Advanced API
Structured explanations
Inspect Why-true steps and Why-false obstacles from one prepared explanation lease.Use text explanations from the Stable Query API when a human-readable document is enough. The Advanced API exposes structured views of the same prepared explanation for applications that need to inspect a derivation step or a failed candidate rule programmatically. It does not run a second explanation search when reading these records.
Types
Defined on this page
| Type | Purpose |
|---|---|
maelys_datalog_explanation_info_t | Kind, completeness and record counts. |
maelys_datalog_explanation_step_view_t | One Why-true derived fact and its premise range. |
maelys_datalog_explanation_premise_view_t | Why-true evidence for one rule-body position. |
maelys_datalog_explanation_obstacle_view_t | Why-false candidate, bindings, support and obstacle. |
maelys_datalog_explanation_support_view_t | One supporting fact inside a Why-false candidate. |
Used from other pages
These types are defined on the linked pages; this page uses them in the roles below.
| Type | Use on this page | Defined in |
|---|---|---|
maelys_datalog_prepared_explanation_t | Input lease whose records are inspected while live. | Stable Querying |
Functions
| Function | Purpose |
|---|---|
maelys_datalog_prepared_explanation_info() | Read counts and completeness before indexing. |
maelys_datalog_prepared_explanation_step() | Read one Why-true step. |
maelys_datalog_prepared_explanation_premise() | Read one Why-true premise. |
maelys_datalog_prepared_explanation_obstacle() | Read one Why-false diagnostic candidate. |
Prepare once, inspect while the result is live
First call the stable prepare function with caller-owned explanation storage. Then read info, followed by indices below its reported counts. A Why-true step contains a premise_begin and premise_count identifying its entries in the shared premise array. Why-false supplies diagnostic obstacle records instead. IDs and indices are local to this one explanation, not durable policy identifiers.
typedef struct {
maelys_datalog_explanation_kind_t kind;
int found, truncated;
size_t step_count, premise_count;
unsigned false_status, false_summary, query_origin, limit_hits;
size_t candidate_rule_count, substitution_count, diagnostic_count, filter_cost_units;
maelys_datalog_fact_t query;
} maelys_datalog_explanation_info_t;typedef struct {
size_t rule_id, premise_begin, premise_count;
maelys_datalog_fact_t fact;
} maelys_datalog_explanation_step_view_t;typedef struct {
unsigned kind, origin, body_index, parent_step;
maelys_datalog_ir_atom_t atom; /* ground fact, absence, or aggregate source */
maelys_datalog_ir_comparison_t op;
maelys_datalog_value_t lhs, rhs, filter_value;
size_t filter_program_index;
unsigned filter_kind, projected_variable;
uint32_t aggregate_value;
} maelys_datalog_explanation_premise_view_t;typedef struct {
unsigned body_index, origin;
maelys_datalog_fact_t fact;
} maelys_datalog_explanation_support_view_t;typedef struct {
size_t rule_id, depth;
maelys_datalog_fact_t target;
uint32_t bound_variable_mask;
maelys_datalog_value_t substitution[MAELYS_DATALOG_IR_MAX_VARIABLES];
size_t support_count;
maelys_datalog_explanation_support_view_t supports[MAELYS_DATALOG_IR_MAX_BODY];
unsigned obstacle_kind, obstacle_origin, body_index, unbound_term_mask;
maelys_datalog_ir_atom_t pattern;
maelys_datalog_ir_comparison_t op;
maelys_datalog_value_t lhs, rhs, filter_value;
size_t filter_program_index;
unsigned filter_kind;
} maelys_datalog_explanation_obstacle_view_t;Read indexed records
maelys_datalog_status_t
maelys_datalog_prepared_explanation_info(
const maelys_datalog_prepared_explanation_t *explanation,
maelys_datalog_explanation_info_t *out_info
);maelys_datalog_status_tOK for a live reference-backend prepared explanation; UNSUPPORTED for another backend.
maelys_datalog_status_t
maelys_datalog_prepared_explanation_step(
const maelys_datalog_prepared_explanation_t *explanation,
size_t index,
maelys_datalog_explanation_step_view_t *out_step
);maelys_datalog_status_tOK for an existing step; NOT_FOUND for an out-of-range index.
maelys_datalog_status_t
maelys_datalog_prepared_explanation_premise(
const maelys_datalog_prepared_explanation_t *explanation,
size_t index,
maelys_datalog_explanation_premise_view_t *out_premise
);maelys_datalog_status_tOK for an existing premise; NOT_FOUND for an out-of-range index.
maelys_datalog_status_t
maelys_datalog_prepared_explanation_obstacle(
const maelys_datalog_prepared_explanation_t *explanation,
size_t index,
maelys_datalog_explanation_obstacle_view_t *out_obstacle
);maelys_datalog_status_tOK for an existing obstacle; NOT_FOUND for an out-of-range index.
static maelys_datalog_status_t inspect_true_steps(
const maelys_datalog_prepared_explanation_t *explanation) {
maelys_datalog_explanation_info_t info = {0};
maelys_datalog_status_t rc = maelys_datalog_prepared_explanation_info(
explanation, &info);
if (rc != MAELYS_DATALOG_STATUS_OK) return rc;
if (info.kind != MAELYS_DATALOG_EXPLAIN_TRUE) return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
for (size_t i = 0; i < info.step_count; ++i) {
maelys_datalog_explanation_step_view_t step = {0};
rc = maelys_datalog_prepared_explanation_step(explanation, i, &step);
if (rc != MAELYS_DATALOG_STATUS_OK) return rc;
/* step.premise_begin and step.premise_count delimit its evidence. */
}
return MAELYS_DATALOG_STATUS_OK;
}Release the prepared explanation before releasing its result; text pointers in views borrow that live result. Do not place output records inside the explanation arena. Structured access is reference-backend-only; another backend returns UNSUPPORTED rather than a fabricated view. A truncated result is an incomplete bounded exploration, not proof that no other explanation exists.