Syntax

An action rule takes the following form:

\begin{displaymath}Agent, Condition, \{Event\} => Action\end{displaymath}

where Agent is an atomic formula that represents a pattern for agents, Condition is a conjunction of in-line conditions on the agents, Event is a non-empty disjunction of patterns for events that can activate the agents, and Action is a sequence of subgoals which can be built-ins, calls of predicates defined in Prolog clauses, matching clauses, or action rules. Condition and the following comma can be omitted if the condition is empty. Action cannot be empty. The subgoal true represents an empty action that always succeeds. An action rule degenerates into a matching clause if Event together with the enclosing braces are missing.

A general event pattern takes the form of event(X,T), where $X$ is a variable, called a channel, and $T$ is a variable that will reference the event object transmitted to the agent from the event poster. If the event object is not used, then the argument T can be omitted and the pattern can be written as event(X). The agent Agent will be attached to the channel X for each event event(X,T) specified in the action rule. In general, an action rule may specify several event patterns. However, co-existing patterns of event/2 must all have the same variable as the second argument so the variable always references the event object when the rule is triggered by an event of any of the patterns.

A channel expression, which takes one of the following forms, specifies agents attached to channels:

The following primitives are provided for posting general-form events:

The event pattern ins(X) indicates that the agent will be activated when any variable in X is instantiated. Notice that X can be any term. If X is a ground term, then the event pattern has no effect. Events of ins(X) are normally posted by built-ins. The user can use the built-in post_ins(X) to post ins events for testing purposes.

A predicate consists of a sequence of action rules defining agents of the same predicate symbol. In a program, predicates defined by action rules can be intermingled with predicates defined by Prolog clauses.

Neng-Fa Zhou 2012-01-03