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.


Field Summary
(package private)  PLTerm Binding
           
private static int lastRef
           
private  int SINGLE_REF
           
(package private)  int VarNumber
           
 
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
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.
 int getNumber()
          Returns the internal variable number.
 boolean isFree()
          free variable test.
 boolean isRunnable()
          Execution test on Prolog objects.
 java.lang.Object javaRepr(PLInterpreter i)
          Java representation of a variable: just itself.
protected  int numberOfCells()
           
 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.
 void unbind()
          Variable unbinding.
 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

VarNumber

int VarNumber

Binding

PLTerm Binding

SINGLE_REF

private final int SINGLE_REF

lastRef

private static int lastRef
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.

getNumber

public int getNumber()
Returns the internal variable number.
Returns:
The internal variable number.

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.
Returns:
The string representation of this variable.
Overrides:
toString in class PLTerm

javaRepr

public java.lang.Object javaRepr(PLInterpreter i)
Java representation of a variable: just itself.
Overrides:
javaRepr in class PLTerm

isRunnable

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

equals

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

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.
Returns:
A PLTerm object with a copy of this variable and its contents.
Overrides:
copy in class PLTerm

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.
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
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.
Overrides:
backtrack in class PLTerm

numberOfCells

protected int numberOfCells()
Overrides:
numberOfCells in class PLTerm