CiaoJava
Class PLStructure

java.lang.Object
  extended byCiaoJava.PLTerm
      extended byCiaoJava.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
 
Fields inherited from class CiaoJava.PLTerm
fail, nil, success
 
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
 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(CiaoJava.PLInterpreter i)
          Java representation of a structure.
 java.lang.String toString()
          String representation of a Prolog structure.
 boolean unify(PLTerm term)
          Term unification.
 
Methods inherited from class CiaoJava.PLTerm
isInteger, isList, isNil, isString, isStructure, isVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.

Specified by:
toString in class PLTerm
Returns:
a Java string that represents the contents of this Prolog structure.

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(CiaoJava.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.

Specified by:
javaRepr in class PLTerm
Parameters:
i - PLInterpreter object used to build the Java representation.
Returns:
a Java object with the Java representation of this Prolog structure.

isRunnable

public boolean isRunnable()
Execution test on Prolog objects. Returns true if the related Prolog term can be evaluated.

Specified by:
isRunnable in class PLTerm
Returns:
Always true (every Prolog structure can be used to represent a Prolog goal).

equals

public boolean equals(PLTerm t)
comparison between Prolog terms.

Specified by:
equals in class PLTerm
Parameters:
t - Prolog term to be compared to.
Returns:
true if this structure is equal to the Prolog term received as argument; false otherwise.

copy

public PLTerm copy()
Makes a full copy of this PLStructure Prolog structure object. Recursively clones the arguments of this term.

Specified by:
copy in class PLTerm
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.

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.

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