CiaoJava
Class PLStructure

java.lang.Object
  |
  +--CiaoJava.PLTerm
        |
        +--CiaoJava.PLStructure

public class PLStructure
extends PLTerm

This class is used to represent in Java the Prolog compound terms. This is the basic construct to manage requests, answers and goals in the Java side of this interface.


Field Summary
(package private)  PLTerm[] Args
           
(package private)  int Arity
           
(package private)  java.lang.String Name
           
 
Fields inherited from class CiaoJava.PLTerm
ATOM, AtomTable, currentVersion, fail, FLOAT, INTEGER, INTERPRETER_ERROR, INTERPRETER_SUCCESS, JAVA_OBJECT, LIST, MAX_READ_BUFFER, nil, PFX_ATOM, PFX_FLOAT, PFX_LIST_WITH_NIL_TAIL, PFX_LIST_WITH_NONIL_TAIL, PFX_LONG_INT, PFX_MULTI_REF_ATOM, PFX_MULTI_REF_STRUCT, PFX_MULTI_REF_VAR, PFX_SHORT_INT, PFX_SINGLE_REF_VAR, PFX_STRUCT, PFXC_ATOM, PFXC_FLOAT, PFXC_INTEGER, PFXC_LIST, PFXC_NIL, PFXC_STRING, PFXC_STRUCT, PFXC_VARIABLE, PROLOG_EXCEPTION, PROLOG_FAIL, PROLOG_QUERY_ID, PROLOG_SUCCESS, STRING, STRING_BUFFER_SIZE, STRUCTURE, success, Type, VarCounter, VARIABLE, VarNumber, VERSION_A, VERSION_C
 
Constructor Summary
PLStructure(java.lang.String name, int arity, PLTerm[] arg)
          Creates a new PLStructure object with the functor, arity and arguments received as parameters.
PLStructure(java.lang.String name, PLTerm[] arg)
          Creates a new PLStructure object.
 
Method Summary
 void backtrack(PLTerm term)
           
 PLTerm copy()
          Makes a full copy of this PLStructure Prolog structure object.
 boolean equals(PLTerm t)
          comparison between Prolog terms.
 PLTerm getArg(int argNumber)
          Returns the argument number argNumber, received as argument.
 PLTerm[] getArgs()
          Returns an array of Prolog terms containing the arguments of this structure.
 int getArity()
          Returns the arity of this Prolog structure.
 java.lang.String getFunctor()
          Returns the functor name of this Prolog structure.
 boolean isRunnable()
          Execution test on Prolog objects.
 java.lang.Object javaRepr(PLInterpreter i)
          Java representation of a structure.
 void launchGoal(PLConnection pl)
          Goal launching.
 void launchGoal(PLInterpreter interpreter, PLConnection pl)
          Goal launching.
protected  int numberOfCells()
           
 java.lang.String toString()
          String representation of a Prolog structure.
 boolean unify(PLTerm term)
          Term unification.
 
Methods inherited from class CiaoJava.PLTerm
fastRead, fastWrite, genPrefix, genTerm, getChar, getFloat, getInt, getPrefix, getString, getTerm, isException, isList, isNil, isPrologFail, isPrologSuccess, isQueryId, isSolution, isString, isStructure, isVariable, launchGoal
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

Name

java.lang.String Name

Arity

int Arity

Args

PLTerm[] Args
Constructor Detail

PLStructure

public PLStructure(java.lang.String name,
                   int arity,
                   PLTerm[] arg)
Creates a new PLStructure object with the functor, arity and arguments received as parameters.
Parameters:
name - Functor name.
arity - Structure arity.
arg - Array of Prolog arguments.

PLStructure

public PLStructure(java.lang.String name,
                   PLTerm[] arg)
Creates a new PLStructure object. Creates the Prolog structure using the functor and argument list received as parameters.
Parameters:
name - Functor name.
arg - Array of Prolog arguments.
Method Detail

toString

public java.lang.String toString()
String representation of a Prolog structure.
Returns:
a Java string that represents the contents of this Prolog structure.
Overrides:
toString in class PLTerm

getFunctor

public java.lang.String getFunctor()
Returns the functor name of this Prolog structure.
Returns:
the string that contains the functor of this Prolog structure.

getArity

public int getArity()
Returns the arity of this Prolog structure.
Returns:
the number of elements of this structure.

getArgs

public PLTerm[] getArgs()
Returns an array of Prolog terms containing the arguments of this structure.
Returns:
a Java array of PLTerm objects that contains the arguments of this structure.

getArg

public PLTerm getArg(int argNumber)
Returns the argument number argNumber, received as argument.
Parameters:
argNumber - Position of the argument to be returned.
Returns:
the Prolog term included in the position argNumber of the argument list.

javaRepr

public java.lang.Object javaRepr(PLInterpreter i)
Java representation of a structure. If this structure refers to a Java object in the object table of the interpreter received as argument, then this Java object is returned. Otherwise, this PLStructure object is returned itself.
Parameters:
i - PLInterpreter object used to build the Java representation.
Returns:
a Java object with the Java representation of this Prolog structure.
Overrides:
javaRepr in class PLTerm

isRunnable

public boolean isRunnable()
Execution test on Prolog objects. Returns true if the related Prolog term can be evaluated.
Returns:
Always true (every Prolog structure can be used to represent a Prolog goal).
Overrides:
isRunnable in class PLTerm

equals

public boolean equals(PLTerm t)
comparison between Prolog terms.
Parameters:
t - Prolog term to be compared to.
Returns:
true if this structure is equal to the Prolog term received as argument; false otherwise.
Overrides:
equals in class PLTerm

copy

public PLTerm copy()
Makes a full copy of this PLStructure Prolog structure object. Recursively clones the arguments of this term.
Returns:
a PLTerm object that contains a full copy of this Prolog structure; that is, no argument is shared between this object and the Prolog term returned.
Overrides:
copy in class PLTerm

unify

public boolean unify(PLTerm term)
Term unification. Unifies this Prolog structure with the term received as argument. This method overrides the one inherited from PLTerm.

Important: The unification is 'two sided': the variables found in the term received as argument could be bound in order to unify the complete terms. In the same way, the variables found in this structure could be bound to unify both terms.

Parameters:
term - Term to unify with.
Returns:
true if the unification is successful: false otherwise.
Overrides:
unify in class PLTerm

backtrack

public void backtrack(PLTerm term)
               throws PLException
Overrides:
backtrack in class PLTerm

numberOfCells

protected int numberOfCells()
Overrides:
numberOfCells in class PLTerm

launchGoal

public void launchGoal(PLInterpreter interpreter,
                       PLConnection pl)
Goal launching. Evaluates this structure as a goal and sends it to the eventStream to be launched by Prolog. Before launching, calculates the values of arguments with the interpreter given, if they must be constructed by Java.
Parameters:
interpreter - PLInterpreter object used to interpret the arguments of this structure before launching to the Prolog process.
pl - PLConnection object that represents the connection to the Prolog process.

launchGoal

public void launchGoal(PLConnection pl)
Goal launching. Evaluates this structure as a goal and prints it to the eventStream to be launched by Prolog.
Parameters:
pl - PLConnection object that represents the connection to the Prolog process.