jess
Class Deffunction

java.lang.Object
  |
  +--jess.Deffunction
All Implemented Interfaces:
java.io.Serializable, Userfunction, Visitable

public class Deffunction
extends java.lang.Object
implements Userfunction, java.io.Serializable, Visitable

Class used to represent Deffunctions (functions defined in the Jess language). Note that you can create these form Java code and add them to a Rete engine using Rete.addUserfunction.

(C) 1998 E.J. Friedman-Hill and the Sandia Corporation

Author:
Ernest J. Friedman-Hill
See Also:
Serialized Form

Inner Class Summary
static class Deffunction.Argument
          Represents a formal paramter to this deffunction.
 
Constructor Summary
Deffunction(java.lang.String name, java.lang.String docstring)
          Create a deffunction
 
Method Summary
 java.lang.Object accept(Visitor v)
           
 void addAction(Funcall fc)
          Add an action to this deffunction.
 void addArgument(java.lang.String name, int type)
          Add a formal argument to this deffunction.
 void addValue(Value val)
          Add a simple value to this deffunction.
 Value call(ValueVector call, Context context)
          Execute this deffunction.
 java.util.Iterator getActions()
          The body of this Deffunction
 java.util.Iterator getArguments()
          The formal parameters to this Deffunction
 java.lang.String getDocstring()
          Fetch the documentation string of this Deffunction
 java.lang.String getName()
          Fetch the name of this Deffunction
 void setDocstring(java.lang.String ds)
          Set the documentation string of this Deffunction
 java.lang.String toString()
          Describe myself
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deffunction

public Deffunction(java.lang.String name,
                   java.lang.String docstring)
Create a deffunction
Parameters:
name - the name of the deffunction
docstring - the documentation string
Method Detail

getName

public final java.lang.String getName()
Fetch the name of this Deffunction
Specified by:
getName in interface Userfunction
Returns:
the name

getDocstring

public final java.lang.String getDocstring()
Fetch the documentation string of this Deffunction
Returns:
the documentation string

setDocstring

public final void setDocstring(java.lang.String ds)
Set the documentation string of this Deffunction
Parameters:
ds - The documentation string

getArguments

public java.util.Iterator getArguments()
The formal parameters to this Deffunction

getActions

public java.util.Iterator getActions()
The body of this Deffunction

addArgument

public void addArgument(java.lang.String name,
                        int type)
                 throws JessException
Add a formal argument to this deffunction. Only the last may be a MULTIVARIABLE. Note that arguments will appear in left-to-right roder acording to the order in which they are added.
Parameters:
name - A name for the variable (without the leading '?')
type - RU.MULTIVARIABLE or RU.VARIABLE

addAction

public void addAction(Funcall fc)
               throws JessException
Add an action to this deffunction. The actions and values added to a deffunction will be stored in the order added, and thereby make up the body of the deffunction.
Parameters:
fc - The action

addValue

public void addValue(Value val)
Add a simple value to this deffunction. The actions and values added to a deffunction will be stored in the order added, and thereby make up the body of the deffunction.
Parameters:
val - The value

call

public Value call(ValueVector call,
                  Context context)
           throws JessException
Execute this deffunction. Evaluate each action or value, in order. If no explicit (return) statement is encountered, the last evaluation result will be returned as the result of this deffunction.
Specified by:
call in interface Userfunction
Parameters:
call - The ValueVector form of the function call used to invoke this deffunction.
c - The execution context
Returns:
As described above.
Throws:
JessException - If anything goes wrong

toString

public java.lang.String toString()
Describe myself
Overrides:
toString in class java.lang.Object
Returns:
a pretty-print representation of this function

accept

public java.lang.Object accept(Visitor v)
Specified by:
accept in interface Visitable

© 1997 E.J. Friedman-Hill and Sandia Corporation