next up previous

9.4.1 Messagehandler Parameters

A messagehandler may accept exactly or at least a specified number of arguments, depending on whether a wildcard parameter is used or not. The regular parameters specify the minimum number of arguments that must be passed to the handler. Each of these parameters may be referenced like a normal single-field variable within the actions of the handler. If a wildcard parameter is present, the handler may be passed any number of arguments greater than or equal to the minimum. If no wildcard parameter is present, then the handler must be passed exactly the number of arguments specified by the regular parameters. All arguments to a handler that do not correspond to a regular parameter are grouped into a multifield value that can be referenced by the wildcard parameter. The standard CLIPS multifield functions, such as length$ and expand$, can be applied to the wildcard parameter.

Handler parameters have no bearing on the applicability of a handler to a particular message (see section 9.5.1). However, if the number of arguments is inappropriate, a message execution error (see section 9.5.4) will be generated when the handler is called. Thus, the number of arguments accepted should be consistent for all message-handlers applicable to a particular message.

Example

CLIPS> (clear)
CLIPS>
(defclass CAR (is-a USER)
  (role concrete)
    (slot front-seat)
    (multislot trunk)
    (slot trunk-count))
CLIPS>
(defmessage-handler CAR put-items-in-car (?item $?rest)
    (bind ?self:front-seat ?item)
    (bind ?self:trunk ?rest)
    (bind ?self:trunk-count (length$ ?rest)))
CLIPS> (make-instance Pinto of CAR)
[Pinto]
CLIPS> (send [Pinto] put-items-in-car bag-of-groceries
        tire suitcase)
2
CLIPS> (send [Pinto] print)
[Pinto] of CAR
(front-seat bag-of-groceries)
(trunk tire suitcase)
(trunk-count 2)
CLIPS>

9.4.1.1 Active Instance Parameter



next up previous