4. Defining Functions in Jess 17 4. Defining Functions in Jess 4.1. Deffunctions You can define your own functions in the Jess rule language using the deffunction construct. A deffunction construct looks like this: (deffunction <function-name> [<doc-comment>] (<parameter>*) <expr>* [<return-specifier>]) The <function-name> must be a symbol. Each <parameter> must be a variable name. The optional <doc-comment> is a double-quoted string that can describe the purpose of the function. There may be an arbitrary number of <expr> expressions. The optional <return-specifier> gives the return value of the function. It can either be an explicit use of the return function or it can be any value or expression. Control flow in deffunction s is achieved via control-flow functions like foreach , if , and while . The following is a deffunction that returns the larger of its two numeric arguments: Jess> (deffunction max (?a ?b) (if (> ?a ?b) then (return ?a) else (return ?b))) TRUE Note that this could have also been written as:
This is the end of the preview. Sign up
access the rest of the document.
This note was uploaded on 03/02/2010 for the course COMP 102 taught by Professor Smith during the Spring '10 term at California State University , Monterey Bay.