jess
Class Funcall

java.lang.Object
  extended by jess.ValueVector
      extended by jess.Funcall
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Visitable

public class Funcall
extends ValueVector
implements java.io.Serializable, Visitable

jess.Funcall is a specialized subclass of ValueVector that represents a Jess function call. It contains the name of the function, an internal pointer to the actual Userfunction object containing the function code, and the arguments to pass to the function.

You can call Jess functions using Funcall if you prefer, rather than using Rete.eval(java.lang.String) This method has somewhat less overhead since there is no parsing to be done, but of course it's less convenient.

 Rete r = new Rete();

 // The following is equivalent to the Jess code
 // (defclass dimension "java.awt.Dimension")
 Funcall f = new Funcall("defclass", r);
 f.arg("dimension").arg("java.awt.Dimension");
 f.execute(r.getGlobalContext());
 

The first entry in a Funcall's ValueVector is the name of the function, even though you don't explicitly set it. Changing the first entry will not automatically change the function the Funcall will call! On the other hand, redefining a function in the Rete object a Funcall is tied to will cause the Funcall to call the new function.

The Funcall class also contains some public static constant Value member objects that represent the special symbols nil, TRUE, FALSE, EOF, etc. You are encouraged to use these.

(C) 2013 Sandia Corporation

See Also:
FuncallValue, Serialized Form

Field Summary
static Value CRLF
          The object representing a newline to printout
static Value EOF
          The object representing end-of-file
static Value FALSE
          The object representing the value FALSE
static Value NIL
          The object representing the value NIL
static Value NILLIST
          An object representing an empty list.
static Value T
          The object representing printout's standard router
static Value TRUE
          The object representing the value TRUE
 
Fields inherited from class jess.ValueVector
m_ptr, m_v
 
Constructor Summary
Funcall(java.lang.String name, Rete engine)
          Create a Funcall given the name.
 
Method Summary
 java.lang.Object accept(Visitor v)
          A proper accept() implementation should call one of the visitXXX() methods on the Visitor.
 Funcall arg(double f)
          Calls ValueVector.add(jess.Value), then returns this object.
 Funcall arg(Funcall f)
          Calls ValueVector.add(jess.Value), then returns this object.
 Funcall arg(int i)
          Calls ValueVector.add(jess.Value), then returns this object.
 Funcall arg(long l)
          Calls ValueVector.add(jess.Value), then returns this object.
 Funcall arg(java.lang.Object o)
          Calls ValueVector.add(jess.Value), then returns this object.
 Funcall arg(java.lang.String s)
          Calls ValueVector.add(jess.Value), then returns this object.
 Funcall arg(Value v)
          Calls ValueVector.add(jess.Value), then returns this object.
 java.lang.Object clone()
          Copies a Funcall
 Value execute(Context context)
          Execute this funcall in a particular context.
 Value get(int i)
          A version of ValueVector.get with more appropriate error messages.
 java.lang.String getName()
          Returns the name of the function this Funcall will invoke
 Userfunction getUserfunction(Rete engine)
          Returns the Userfunction object this Funcall would invoke if it were invoked now,
static java.util.Iterator listIntrinsics()
          Lists all the functions built into this version of Jess.
 void reset()
           
 java.lang.String toString()
          Formats a Funcall as a String
 java.lang.String toStringWithParens()
          Just calls toString()
 
Methods inherited from class jess.ValueVector
add, add, add, add, add, add, add, addAll, addAll, cloneInto, contains, copy, equals, hashCode, remove, set, setLength, size
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

public static Value TRUE
The object representing the value TRUE


FALSE

public static Value FALSE
The object representing the value FALSE


NIL

public static Value NIL
The object representing the value NIL


NILLIST

public static Value NILLIST
An object representing an empty list.


EOF

public static Value EOF
The object representing end-of-file


CRLF

public static Value CRLF
The object representing a newline to printout


T

public static Value T
The object representing printout's standard router

Constructor Detail

Funcall

public Funcall(java.lang.String name,
               Rete engine)
        throws JessException
Create a Funcall given the name. The Funcall's arguments must then be added using methods inherited from ValueVector.

Parameters:
name - The name of the function
engine - The Rete engine where the function is defined
Throws:
JessException - If something goes wrong.
Method Detail

toString

public java.lang.String toString()
Formats a Funcall as a String

Overrides:
toString in class ValueVector
Returns:
The pretty-print form of this Funcall

toStringWithParens

public java.lang.String toStringWithParens()
Just calls toString()

Overrides:
toStringWithParens in class ValueVector
Returns:
the pretty-print form of this Funcall

listIntrinsics

public static java.util.Iterator listIntrinsics()
Lists all the functions built into this version of Jess.

Returns:
the Iterator

getName

public java.lang.String getName()
Returns the name of the function this Funcall will invoke

Returns:
the name of the function

clone

public java.lang.Object clone()
Copies a Funcall

Overrides:
clone in class ValueVector
Returns:
A copy of the Funcall

execute

public Value execute(Context context)
              throws JessException
Execute this funcall in a particular context.

Parameters:
context - An execution context for the function
Returns:
The result of the function call
Throws:
JessException - If something goes wrong

getUserfunction

public Userfunction getUserfunction(Rete engine)
                             throws JessException
Returns the Userfunction object this Funcall would invoke if it were invoked now,

Parameters:
engine - the Rete object that will supply the execution context
Returns:
the Userfunction object
Throws:
JessException

arg

public Funcall arg(Value v)
Calls ValueVector.add(jess.Value), then returns this object. This method does the same thing as add but returns this Funcall as a Funcall so the last call in a chain can be a call to execute(jess.Context).

Parameters:
v - An argument to add to this Funcall
Returns:
This Funcall
See Also:
ValueVector.add(jess.Value)

arg

public Funcall arg(java.lang.String s)
            throws JessException
Calls ValueVector.add(jess.Value), then returns this object. This method does the same thing as add but returns this Funcall as a Funcall so the last call in a chain can be a call to execute(jess.Context).

Parameters:
s - An argument to add to this Funcall, interpreted as a symbol
Returns:
This Funcall
Throws:
JessException
See Also:
ValueVector.add(jess.Value)

arg

public Funcall arg(int i)
            throws JessException
Calls ValueVector.add(jess.Value), then returns this object. This method does the same thing as add but returns this Funcall as a Funcall so the last call in a chain can be a call to execute(jess.Context).

Parameters:
i - An argument to add to this Funcall, interpreted as an integer
Returns:
This Funcall
Throws:
JessException
See Also:
ValueVector.add(jess.Value)

arg

public Funcall arg(double f)
            throws JessException
Calls ValueVector.add(jess.Value), then returns this object. This method does the same thing as add but returns this Funcall as a Funcall so the last call in a chain can be a call to execute(jess.Context).

Parameters:
f - An argument to add to this Funcall, interpreted as an integer
Returns:
This Funcall
Throws:
JessException
See Also:
ValueVector.add(jess.Value)

arg

public Funcall arg(long l)
            throws JessException
Calls ValueVector.add(jess.Value), then returns this object. This method does the same thing as add but returns this Funcall as a Funcall so the last call in a chain can be a call to execute(jess.Context).

Parameters:
l - An argument to add to this Funcall, interpreted as a long
Returns:
This Funcall
Throws:
JessException
See Also:
ValueVector.add(jess.Value)

arg

public Funcall arg(Funcall f)
            throws JessException
Calls ValueVector.add(jess.Value), then returns this object. This method does the same thing as add but returns this Funcall as a Funcall so the last call in a chain can be a call to execute(jess.Context).

Parameters:
f - An argument to add to this Funcall, interpreted as a function call
Returns:
This Funcall
Throws:
JessException
See Also:
ValueVector.add(jess.Value)

arg

public Funcall arg(java.lang.Object o)
Calls ValueVector.add(jess.Value), then returns this object. This method does the same thing as add but returns this Funcall as a Funcall so the last call in a chain can be a call to execute(jess.Context).

Parameters:
o - An argument to add to this Funcall, interpreted as a Java object
Returns:
This Funcall
See Also:
ValueVector.add(jess.Value)

get

public Value get(int i)
          throws JessException
A version of ValueVector.get with more appropriate error messages. Fetch the entry at position i in this Funcall.

Overrides:
get in class ValueVector
Parameters:
i - The 0-based index of the Value to fetch
Returns:
The Value
Throws:
JessException

accept

public java.lang.Object accept(Visitor v)
Description copied from interface: Visitable
A proper accept() implementation should call one of the visitXXX() methods on the Visitor.

Specified by:
accept in interface Visitable
Parameters:
v - a visitor to invoke
Returns:
whatever the invoked Visitor method returns.

reset

public void reset()

2013 Sandia Corporation