B-Prolog - Action Rules

Action Rules

The lack of a facility for programming "active" sub-goals that can be reactive to the environment has been considered one of the weaknesses of logic programming. To overcome this, B-Prolog provides a simple and yet powerful language, called Action Rules (AR), for programming agents. An agent is a subgoal that can be delayed and can later be activated by events. Each time an agent is activated, some action may be executed. Agents are a more general notion than delay constructs in early Prolog systems and processes in concurrent logic programming languages in the sense that agents can be responsive to various kinds of events including instantiation, domain, time, and user-defined events.

An action rule takes the following

H, G, {E} => B

where H is a pattern for agents, G is a sequence of conditions on the agents, E is a set of patterns for events that can activate the agents, and B is a sequence of actions performed by the agents when they are activated. When the event pattern E together with the enclosing braces is missing, an action rule degenerates into a matching clause.

A set of built-in events is provided for programming constraint propagators and interactive graphical user interfaces. For example, ins(X) is an event that is posted when the variable X is instantiated. A user program can create and post its own events and define agents to handle them. A user-defined event takes the form of event(X,O) where X is a variable, called a suspension variable, that connects the event with its handling agents, and O is a Prolog term that contains the information to be transmitted to the agents. The built-in post(E) posts the event E.

Consider the following examples:

echo(X),{event(X,Mes)}=>writeln(Mes). ping(T),{time(T)} => writeln(ping).

The agent echo(X) echoes whatever message it receives. For example,

?-echo(X),post(event(X,hello)),post(event(X,world)).

outputs the message hello followed by world. The agent ping(T) responds to time events from the timer T. Each time it receives a time event, it prints the message ping. For example,

?-timer(T,1000),ping(T),repeat,fail.

creates a timer that posts a time event every second and creates an agent ping(T) to respond to the events. The loop after the agent is needed to make the agent perpetual.

AR has been found useful for programming simple concurrency, implementing constraint propagators, and developing interactive graphical user interfaces. It has served as an intermediate language for compiling Constraint Handling Rules (CHR) and Answer Set Programs (ASP).

Read more about this topic:  B-Prolog

Famous quotes containing the words action and/or rules:

    U.S. international and security policy ... has as its primary goal the preservation of what we might call “the Fifth Freedom,” understood crudely but with a fair degree of accuracy as the freedom to rob, to exploit and to dominate, to undertake any course of action to ensure that existing privilege is protected and advanced.
    Noam Chomsky (b. 1928)

    However diligent she may be, however dedicated, no mother can escape the larger influences of culture, biology, fate . . . until we can actually live in a society where mothers and children genuinely matter, ours is an essentially powerless responsibility. Mothers carry out most of the work orders, but most of the rules governing our lives are shaped by outside influences.
    Mary Kay Blakely (20th century)