next up previous

12.6.7 Return

The return function immediately terminates the currently executing deffunction, generic function method, message-handler, defrule RHS, or certain instance set query functions (do-for-instance, do-for-all-instances and delayed-do-for-all-instances). Without any arguments, there is no return value. However, if an argument is included, its evaluation is given as the return value of the deffunction , method or message-handler.

The return function can only be used within the actions of deffunctions, methods and message-handlers, defrules, or the instance set query functions previously listed. If used on the RHS of a rule, the current focus is removed from the focus stack. In addition, return should not be used as an argument to another function call. If used within an instance set query function, the return function is only valid if it is applicable in the outer scope of the query.

Syntax

(return [<expression>])

Example

CLIPS>
(deffunction sign (?num)
  (if (> ?num 0) then
     (return 1))
  (if (< ?num 0) then
     (return -1))
  0)
CLIPS> (sign 5)
1
CLIPS> (sign -10)
-1
CLIPS> (sign 0)
0
CLIPS>


next up previous