NAME

Logic::Relational::Program - Represents the mutable relational logic program.

SYNOPSIS

use Logic::Relational::Program;
my $program = Logic::Relational::Program->new;
$program->fact(thief => 'badguy');

DESCRIPTION

Logic::Relational::Program manages the knowledge base containing facts and rules. It supports transaction isolation (atomicity on commits/rollbacks) and snapshot semantics for active queries.

METHODS

new

Constructor.

fact

Asserts a fact. Can take a Logic::Relational::Clause object, or a predicate name and arguments. Returns the generated clause ID.

rule

Asserts a rule. Takes head (Term or Call goal), body (Goal), and metadata (optional). Returns the generated clause ID.

retract

Retracts the first clause whose head unifies with the pattern. Returns 1 if a clause was retracted, 0 otherwise.

retract_all

Retracts all clauses whose heads unify with the pattern. Returns the number of retracted clauses.

retract_clause

Retracts a clause with the exact ID. Throws an exception if the ID does not exist.

clauses_for

Introspection method. Returns a list of Logic::Relational::Clause objects for the given name and arity.

query

Creates and returns a Logic::Relational::Query snapshot query object.

transaction

Executes a coderef atomically. If the block throws an exception, all changes are rolled back.