prologj
Interface PrologBoundTerm


public interface PrologBoundTerm

Part of the PrologJ java API. This interface is implemented by objects encapsulating a Prolog term, together with the names and bound values (if any) of variables occurring in it.


Method Summary
 java.lang.Object getBinding(int number)
          Accessor for the binding of a variable specified by relative position
 java.lang.Object getBinding(java.lang.String name)
          Accessor for the binding of a variable specified by name
 int getNumberOfVariables()
          Accessor for the number of variables in the encapsulated term
 java.lang.Object getTerm()
          Accessor for the encapsulated term.
 void setVariable(int number, java.lang.Object value)
          Set a variable to a particular value before using the term encapsulated in this in a computation.
 void setVariable(java.lang.String name, java.lang.Object value)
          Set a variable to a particular value before using the term encapsulated in this in a computation.
 

Method Detail

getNumberOfVariables

public int getNumberOfVariables()
Accessor for the number of variables in the encapsulated term

Returns:
the number of unique variables in the encapsulated term. Each named variable that occurs is counted once, no matter how many times it appears. The anonymous variable (_) is counted each time it appears.

getBinding

public java.lang.Object getBinding(java.lang.String name)
                            throws java.lang.IllegalArgumentException
Accessor for the binding of a variable specified by name

Parameters:
name - the name of the variable
Returns:
the current binding for the variable of this name, or null if specified variable is unbound.
Throws:
java.lang.IllegalArgumentException - if the parameter is "_", or no variable of the specified name occurs in the term.

getBinding

public java.lang.Object getBinding(int number)
                            throws java.lang.ArrayIndexOutOfBoundsException
Accessor for the binding of a variable specified by relative position

Parameters:
number - the number of the variable. Named variables are numbered 0, 1 ... in the order of first occurrence in the term. The anonymous variable (_) is given a new number each time it occurs.
Returns:
the current binding for the specified variable, or null if specified variable is unbound.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if number does not lie in 0 .. number of variables in the term - 1

setVariable

public void setVariable(java.lang.String name,
                        java.lang.Object value)
                 throws java.lang.IllegalArgumentException
Set a variable to a particular value before using the term encapsulated in this in a computation. This method is meant to be invoked before the computation, with the variable not yet bound. The variable remains set to the value specified until another set() operation on the same variable is done. The variable is specified by name

Parameters:
name - the name of the variable
value - the value to set it to. "Setting" a value to null restores it to the unset state.
Throws:
java.lang.IllegalArgumentException - if the parameter is "_", or no variable of the specified name occurs in the term.

setVariable

public void setVariable(int number,
                        java.lang.Object value)
                 throws java.lang.ArrayIndexOutOfBoundsException
Set a variable to a particular value before using the term encapsulated in this in a computation. This method is meant to be invoked before the computation, with the variable not yet bound. The variable remains set to the value specified until another set() operation on the same variable is done. The variable is specified by relative position.

Parameters:
number - the number of the variable. Named variables are numbered 0, 1 ... in the order of first occurrence in the term. The anonymous variable (_) is given a new number each time it occurs.
value - the value to set it to. "Setting" a value to null restores it to the unset state.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if number does not lie in 0 .. number of variables in the term - 1.

getTerm

public java.lang.Object getTerm()
Accessor for the encapsulated term. This method is meant to only be used by PrologJ implementation routines.

Returns:
the encapsulated term