Syntax

An action rule takes the following form:

Agent, Condition, {Event} => Action

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 its enclosing braces, is 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 that is 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) that is 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 that 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 that are 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. Note that X can be any term. If X is a ground term, then the event pattern does not have any effect. Events of ins(X) are normally posted by built-ins. Users can use the built-in post_ins(X) in order to post ins events for testing purposes.

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

Neng-Fa Zhou 2013-01-25