Jess Control Structures

List of control structures that can be used by Jess.


8.15. (apply <expression>+)

Package:
LispFunctions
Arguments:
One or more expressions
Returns:
An expression
Description:
Returns the result of calling the first argument, as a Jess function, on all the remaining arguments. The strength of this method lies in the fact that you can call a function whose name, for instance, is in a Jess variable.

8.28. (call-on-engine <external-address> <jess-code>)

Package:
MiscFunctions
Arguments:
an external address (must be a jess.Rete object), and an executable snippet of Jess code
Returns:
(Varies)
Description:
Executes some Jess code in the context of the given Rete object. This is a nice way to send messages between multiple Rete engines in one process. Note that the current variable context is used to evaluate the code, so (for instance) all defglobal values will be from the calling engine, not the target.

8.59. (foreach <variable> <multifield-expression> <action>*)

Package:
Intrinsics
Arguments:
A variable, a multifield expression, and zero or more arguments
Returns:
Varies
Description:
The named variable is set to each of the values in the multifield in turn; for each value, all of the other arguments are evaluated in order. The return function can be used to break the iteration.

Example:

(foreach ?x (create$ a b c d) (printout t ?x crlf))

8.68. (if <expression> then <action>* [else <action>*])

Package:
Intrinsics
Arguments:
A Boolean variable or function call returning Boolean, the atom then, and any number of additional expressions; optionally followed by the atom else another list of expression.
Returns:
(Varies)
Description:
Allows conditional execution of a group of actions. The boolean expression is evaluated. If it does not evaluate to FALSE, the first list of expressions is evaluated, and the return value is that returned by the last expression of that list. If it does evaluate to FALSE, and the optional second list of expressions is supplied, those expressions are evaluated and the value of the last is returned.

Example:

    (if (> ?x 100)
        then
          (printout t "X is big" crlf)
        else
          (printout t "X is small" crlf))

8.109. (progn <expression>+)

Package:
LispFunctions
Arguments:
One or more expressions
Returns:
The result of evaluating the last expression.
Description:
A simple control structure that allows you to group multiple function calls where syntactically only one is allowed - for instance, on the LHS of a rule.

8.118. (return [<expression>])

Package:
Intrinsics
Arguments:
An optional expression
Returns:
(Varies)
Description:
Returns the given value from a deffunction. Exits the deffunction immediately.

8.162. (while <expression> [do] <action>*)

Package:
Intrinsics
Arguments:
A Boolean value or a function call returning Boolean, the atom do, and zero or more expressions
Returns:
(Varies)
Description:
Allows conditional looping. Evaluates the boolean expression repeatedly. As long as it does not equal FALSE, the list of other expressions are evaluated. The value of the last expression evaluated is the return value.