Jess71p2 25 - 4 Defining Functions in Jess 4.1 Deffunctions...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
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:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Ask a homework question - tutors are online