defproduction [Macro]


Purpose

The defproduction macro defines or redefines a production. A Loom production is a data-directed rule that causes an action to be performed whenever a particular kind of event is detected.

Syntax

defproduction name &key when perform schedule do priority

Arguments

The name argument is a non-nil symbol. Productions cannot have the same name as an existing action.

The when argument is the trigger condition for the production. It consists of either a production expression, or a conjunction of production expressions and query expressions (see retrieve Remarks). A production expression describes a transition (see Remarks below). It is a list containing the keyword :detects, :undetects, or :changes, followed by a literal or conjunction of literals, where a literal has the form (ConceptName ?Var) or (RelationName ?Var ?Var).

The perform and schedule arguments specify a task to be performed or scheduled when the production fires. The perform option causes the task to be executed as soon as the production fires, while the schedule option places it on a queue for later execution. The perform and schedule arguments are action expressions consisting of a Loom action name followed by one or more variables or constants. Any ?-variables must have been bound in the when expression.

The do argument specifies a Lisp program to be run when the production fires. It consists of a list of Lisp forms containing ?-variables bound in the when expression.

The priority argument indicates the queue on which a scheduled task is to be placed. It has the values :high or :low---the default being :high. This is a no-op unless a schedule argument is supplied.

Value

The defined or redefined production is returned.

Remarks

The defproduction macro must have a when argument. It must also have exactly one perform, schedule, or do argument.

A :detects production expression is true if its query became satisfied during the most recent state change. An :undetects expression is true if its query ceased to be satisfied during the most recent state change. A :changes expression is true if the fillers of the specified role changed during the most recent state change.

Note that (:detects (:and A B)) is not equivalent to (:and(:detects A) (:detects B)). The latter form requires that bothtransitions happen at the same time, while the former does not.

Production rules cannot trigger on concepts or relation that have no primitiveness, or that are marked :monotonic or :perfect.

Currently, concepts and relations referenced in the when clause of a production must be defined before the production itself is defined.

Production firing results from an explicit or implicit call to new-time-point. All productions fire before any scheduled tasks are performed.

Examples

(defproduction container-and-almost-full
    :when (:detects (:and (Container ?x)
                          (>= (pct-full ?x) 90)))
    :perform (move ?x)) ==> |PRODUCTION|CONTAINER-AND-ALMOST-FULL
(defproduction almost-full-container
    :when (:and (Container ?x)
                (:detects (>= (pct-full ?x) 90)))
    :perform (move ?x)) ==> |PRODUCTION|ALMOST-FULL-CONTAINER
(defproduction P1
    :when (:and (:undetects (A ?x))
                (:for-some (?y) (:and (r ?x ?y) (A ?y))))
    :schedule (foo ?x 3)
    :priority :high) ==> |PRODUCTION|P1
(defproduction P2                    
    :when (:changes (r ?x))
    :do ((print (get-universal-time))
         (format t "The r of \verb+~S+ is now \verb+~S~%+" 
                   ?x (get-value ?x 'r)))) ==> |PRODUCTION|P2

See Also

Last modified: Jun 1 1995