CiaoJava
Class PLVariable

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

public class PLVariable
extends PLTerm

Prolog variables representation. This class represents a Prolog variable, to provide a Prolog style of variable instancing. This class uses the characteristic Java representation of objects as references. If the object referenced by a variable changes, the variable content will change too. This allows to provide a Prolog behaviour of Java variables containing PLVariable objects.


Fields inherited from class CiaoJava.PLTerm
fail, nil, success
 
Constructor Summary
PLVariable()
          Creates a new Prolog variable and references it to a free variable number.
PLVariable(int number)
          Creates a new Prolog variable with a given variable number.
 
Method Summary
 void backtrack(PLTerm term)
          Undo the unification made on this variable using as pattern the term received as argument.
 void bind(PLTerm term)
          Variable binding.
 PLTerm copy()
          Makes a full copy of this PLVariable Prolog variable object.
 boolean equals(PLTerm t)
          Strict comparison between Prolog terms.
 PLTerm getBinding()
          Returns the binding of this Prolog variable.
 boolean isFree()
          free variable test.
 boolean isRunnable()
          Execution test on Prolog objects.
 java.lang.Object javaRepr(CiaoJava.PLInterpreter i)
          Java representation of a variable: just itself.
 java.lang.String toString()
          Returns the string representation of this Prolog variable.
 void unbind()
          Variable unbinding.
 boolean unify(PLTerm term)
          Term unification.
 
Methods inherited from class CiaoJava.PLTerm
isList, isNil, isString, isStructure, isVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PLVariable

public PLVariable()
Creates a new Prolog variable and references it to a free variable number.

PLVariable

public PLVariable(int number)
Creates a new Prolog variable with a given variable number.
Parameters:
number - variable number.
Method Detail

isFree

public boolean isFree()
free variable test. Returns true if this Prolog variable is unbound.
Returns:
true if this Prolog variable is unbound< false if is bound to anothe Prolog term.

getBinding

public PLTerm getBinding()
Returns the binding of this Prolog variable. If this variable is free, returns null.
Returns:
the current binding of this variable.

bind

public void bind(PLTerm term)
Variable binding. Binds the Prolog variable represented by this object to a Prolog term. If the variable is already bound, the binding is replaced with this one.
Parameters:
term - Term to bind to.

unbind

public void unbind()
Variable unbinding. Uninstantiates this Prolog variable, by setting null to the binding attribute.

toString

public java.lang.String toString()
Returns the string representation of this Prolog variable. If the variable is bound to a Prolog term, this term is also represented enclosed between brackets.
Overrides:
toString in class PLTerm
Returns:
The string representation of this variable.

javaRepr

public java.lang.Object javaRepr(CiaoJava.PLInterpreter i)
Java representation of a variable: just itself.
Overrides:
javaRepr in class PLTerm
Following copied from class: CiaoJava.PLTerm
Parameters:
i - PLInterpreter object used to interpret the Prolog representation of Java objects.
Returns:
a Java object representation of the Prolog term.

isRunnable

public boolean isRunnable()
Execution test on Prolog objects. This method is included for implementing the PLTerm abstract method.
Overrides:
isRunnable in class PLTerm
Returns:
Always false.

equals

public boolean equals(PLTerm t)
Strict comparison between Prolog terms.
Overrides:
equals in class PLTerm
Returns:
true if the PLTerm object is exactly a PLVariable object and has the same variable number< false otherwise.

copy

public PLTerm copy()
Makes a full copy of this PLVariable Prolog variable object. Recursively clones the term bound by this variable, in order to create a new PLVariable with no shared components.
Overrides:
copy in class PLTerm
Returns:
A PLTerm object with a copy of this variable and its contents.

unify

public boolean unify(PLTerm term)
Term unification. Unifies this Prolog variable with the term received as argument. If this is a free variable, binds it to the term received as argument. If not, tries to unify the binding with the term received.
Overrides:
unify in class PLTerm
Parameters:
term - Term to unify with.
Returns:
true if the unification is successful: false otherwise.

backtrack

public void backtrack(PLTerm term)
               throws PLException
Undo the unification made on this variable using as pattern the term received as argument.
Parameters:
term - PLTerm object that contains the PLVariable object with the content to be stored on this variable.