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:
- X: A channel variable indicates the agents that are attached to the channel.
-
: A conjunction of channel variables indicates the set of agents that are attached to all of the channels.
-
: A disjunction of channel variables indicates the set of agents that are attached to at least one of the channels.
The following primitives are provided for posting general-form events:
- post_event(C,T): Posts a general-form event to the agents that are attached to the channels that are specified by the channel expression C. The activated agents are first connected to the chain of active agents, and are then executed one at a time. Therefore, agents are activated in a breadth-first fasion.
- post_event_df(C,T): This is the same as post_event(C,T), except agents are activated in a depth-first fasion. The activated agents are added to the active chain one at a time.
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.
- post_ins(X): Posts an ins(X) event, where X must be a channel variable.12.1
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