ThermostatAgentKt
A self-contained reactive agent whose control loop is written in Prolog but whose sensor/actuator primitives are implemented in Kotlin, demonstrating how to embed a it.unibo.tuprolog.solve.Solver inside a regular JVM Thread to bridge logic programming with imperative, stateful host code.
The agent exposes its simulated temperature to the Prolog program through a custom get_temp/1 primitive (a it.unibo.tuprolog.solve.primitive.UnaryPredicate.Functional, i.e. a function-like predicate computing a single substitution), and lets the Prolog program change it through a custom push/1 primitive (a it.unibo.tuprolog.solve.primitive.UnaryPredicate.Predicative, i.e. a predicate that either succeeds or fails without producing bindings). The control logic itself lives in the bundled thermostat.pl resource, templated with coldThreshold and hotThreshold before being parsed by it.unibo.tuprolog.theory.parsing.ClausesParser: it repeatedly reads the temperature and pushes hot or cold air until it settles within range.
This class is the Kotlin counterpart of the it.unibo.tuprolog.examples.solve.ThermostatAgent Java class in this same module, which implements the identical agent using the Java API surface of :solve instead of its Kotlin DSL/extension conveniences (e.g. mgu as a member rather than via request.getUnificator().mgu(...)).
Parameters
the thread name, forwarded to Thread.
the temperature at or below which the agent pushes hot air.
the temperature at or above which the agent pushes cold air.
the starting value of temperature.
Properties
Functions
Parses the templated thermostat.pl program, builds a it.unibo.tuprolog.solve.Solver registering get_temp/1 and push/1 under the libs.agency.thermostat library alias (with it.unibo.tuprolog.solve.flags.TrackVariables turned on so bound variables remain visible in the solution), and runs the start/0 goal once to completion, printing the outcome (reached target temperature, logic failure, or an exception with its Prolog stack trace) to standard output.