PrologEngine class
High-level Dart API for the Prolog engine.
Provides a clean, idiomatic interface for embedding Prolog in Dart applications.
Example:
final prolog = PrologEngine();
prolog.assertz('parent(tom, bob)');
prolog.assertz('parent(bob, ann)');
await for (final solution in prolog.query('parent(X, Y)')) {
print('${solution['X']} is parent of ${solution['Y']}');
}
Constructors
- PrologEngine({Database? database, BuiltinRegistry? builtins, StreamManager? streamManager})
-
Creates a new Prolog engine.
factory
Properties
- builtins → BuiltinRegistry
-
Returns the built-in registry (for advanced usage).
no setter
- clauseCount → int
-
Returns the number of clauses in the database.
no setter
- database → Database
-
Returns the database (for advanced usage).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns true if the database is empty.
no setter
- resolver → Resolver
-
Returns the resolver (for advanced usage).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- streamManager → StreamManager
-
Returns the stream manager (for I/O operations).
no setter
Methods
-
asserta(
dynamic input) → void - Asserts a clause at the beginning of the database.
-
assertTerm(
dynamic input) → void - Asserts a term (handles DCG rules automatically).
-
assertz(
dynamic input) → void - Asserts a clause at the end of the database.
-
clausesByPredicate(
) → Map< String, List< Clause> > - Returns clauses grouped by predicate indicator.
-
clear(
) → void - Clears all clauses from the database.
-
listAll(
) → Iterable< Clause> - Lists all clauses in the database.
-
listByIndicator(
String indicator) → Iterable< Clause> - Lists all clauses for a specific predicate indicator (e.g., 'parent/2').
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
predicateIndicators(
) → Set< String> - Returns all unique predicate indicators in the database.
-
query(
dynamic input) → Stream< Solution> - Queries the database and returns a stream of solutions.
-
queryAll(
dynamic input) → Future< List< Solution> > - Queries the database and returns all solutions.
-
queryOnce(
dynamic input) → Future< QueryResult> - Queries the database and returns the first solution, or null if none.
-
registerForeign(
String name, int arity, BuiltinPredicate implementation) → void - Registers a foreign predicate (Dart function callable from Prolog).
-
retract(
dynamic input) → bool - Retracts the first clause matching the given pattern.
-
retractAll(
dynamic input) → int - Retracts all clauses matching the given head pattern.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited