Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

alice.tuprolog
Class Var  view Var download Var.java

java.lang.Object
  extended byalice.tuprolog.Term
      extended byalice.tuprolog.Var
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Var
extends Term

prolog variable implementation. Variable identificators are time (a long) and a name (a string). Name is used to identify the variable from the point of view of an external user, time as internal code.


Field Summary
static Var ANY
           
(package private)  Term link
           
(package private)  int mark
           
 java.lang.String name
           
(package private)  int time
           
 
Fields inherited from class alice.tuprolog.Term
FALSE, FLOAT, id, INT, NULL, OBJECT, STRUCT, TRUE, VAR
 
Constructor Summary
  Var()
          creates an ANY variable ("_")
  Var(java.lang.String n)
          creates a variable identified by name n
(package private) Var(java.lang.String n, int t)
           
 
Method Summary
 Term copy(alice.util.LinkedList vl)
          copying a var.
 Var findFromNameIn(alice.util.LinkedList vl)
          finds a var Term of the list with the same Name of current Term.
private  Var findIn(alice.util.LinkedList vl)
          finds a var Term of the list with the same time of current Term.
private  boolean findIn(Struct t)
          finds var occurence in a Struct, doing occur-check.
 void free(int m)
          ununification by means of the code m (only link with code greater or equal than m are free)
 java.lang.String getName()
          significant only for Var and Struct derived class.
 Term getTerm()
          gets the real term.
 Term getVar(java.lang.String name_)
          significant only for Struct derived class.
 boolean isAny()
          is it a prolog any(_) variable?
 boolean isAtom()
          is it a prolog (alphanumeric) atom?
 boolean isClause()
          is it a prolog clause?
 boolean isCompound()
          is it a prolog compound term?
 boolean isConst()
          is it a constant prolog term?
 boolean isEmptyList()
          is it a prolog empty list?
 boolean isEQU(Term t)
          is term equal to term t?
 boolean isGround()
          is it a ground term?
 boolean isGT(Term t)
          is term greater than term t?
 boolean isList()
          is it a prolog list?
 boolean isNum()
          is it a prolog numeric term?
 boolean match(Term t)
          matching without unification; only true or false, without bindings.
static int rename(alice.util.LinkedList vl, int c, boolean f)
          renaming of all the variables of the argument list.
(package private)  int renameVars(alice.util.LinkedList vars, int count)
           
 java.lang.String toString()
          gets string representation of the var.
 java.lang.String toStringFlattened()
          get the flat string representation of a variable.
 boolean unify(Term t, int m)
          var unification.
 void unlink()
          unlinks linked var.
 
Methods inherited from class alice.tuprolog.Term
clone, getDouble, getFloat, getInt, getIterator, getLong, getObject, getObject, getString, getStruct, getStruct, getTerm, isFalse, isFloat, isInt, isObject, isStruct, isTrue, isVar, parse, parse, parseSentence, renameVars, toRawString, toString, toStringAsArg, toStringAsArgX, toStringAsArgY
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANY

public static final Var ANY

name

public java.lang.String name

time

int time

link

Term link

mark

int mark
Constructor Detail

Var

public Var(java.lang.String n)
    throws InvalidVarNameException
creates a variable identified by name n


Var

public Var()
creates an ANY variable ("_")


Var

Var(java.lang.String n,
    int t)
Method Detail

getName

public java.lang.String getName()
Description copied from class: Term
significant only for Var and Struct derived class.

Overrides:
getName in class Term

getVar

public Term getVar(java.lang.String name_)
Description copied from class: Term
significant only for Struct derived class.

Overrides:
getVar in class Term

getTerm

public Term getTerm()
gets the real term.

for unbound var it's the var itself, while for bound var it's the linked term

Overrides:
getTerm in class Term

isConst

public boolean isConst()
Description copied from class: Term
is it a constant prolog term?

Overrides:
isConst in class Term

isNum

public boolean isNum()
Description copied from class: Term
is it a prolog numeric term?

Overrides:
isNum in class Term

isCompound

public boolean isCompound()
Description copied from class: Term
is it a prolog compound term?

Overrides:
isCompound in class Term

isAtom

public boolean isAtom()
Description copied from class: Term
is it a prolog (alphanumeric) atom?

Overrides:
isAtom in class Term

isClause

public boolean isClause()
Description copied from class: Term
is it a prolog clause?

Overrides:
isClause in class Term

isList

public boolean isList()
Description copied from class: Term
is it a prolog list?

Overrides:
isList in class Term

isEmptyList

public boolean isEmptyList()
Description copied from class: Term
is it a prolog empty list?

Overrides:
isEmptyList in class Term

isGround

public boolean isGround()
Description copied from class: Term
is it a ground term?

Overrides:
isGround in class Term

isAny

public boolean isAny()
Description copied from class: Term
is it a prolog any(_) variable?

Overrides:
isAny in class Term

findIn

private Var findIn(alice.util.LinkedList vl)
finds a var Term of the list with the same time of current Term.


findFromNameIn

public Var findFromNameIn(alice.util.LinkedList vl)
finds a var Term of the list with the same Name of current Term.


findIn

private boolean findIn(Struct t)
finds var occurence in a Struct, doing occur-check.


renameVars

int renameVars(alice.util.LinkedList vars,
               int count)
Overrides:
renameVars in class Term

rename

public static int rename(alice.util.LinkedList vl,
                         int c,
                         boolean f)
renaming of all the variables of the argument list.


unify

public boolean unify(Term t,
                     int m)
var unification.

First, verify the Term eventually already unified with the same Var if the Term exist, unify var with that term, in order to handle situation as (A = p(X) , A = p(1)) which must produce X/1.

If instead the var is not already unified, then:

if the Term is a var bound to X, then try unification with X so for example if A=1, B=A then B is unified to 1 and not to A (note that it's coherent with chronological backtracking: the eventually backtracked A unification is always after backtracking of B unification.

if are the same Var, unification must succeed, but without any new bindings (to avoid cycles for extends in A = B, B = A)

if the term is a number, then it's a success and new link is created (retractable by means of a code)

if the term is a compound, then occur check test is executed: the var must not appear in the compound ( avoid X=p(X), or p(X,X)=p(Y,f(Y)) ); if occur check is ok then it's success and a new link is created (retractable by a code)

Overrides:
unify in class Term

match

public boolean match(Term t)
Description copied from class: Term
matching without unification; only true or false, without bindings.

Overrides:
match in class Term

free

public void free(int m)
ununification by means of the code m (only link with code greater or equal than m are free)

Overrides:
free in class Term

unlink

public void unlink()
unlinks linked var.

(not used by prolog core; only for extension and not prolog manipulation )


copy

public Term copy(alice.util.LinkedList vl)
copying a var.

if bound var then copying of the term linked, else the list passed as arg are variables already linked, so

if current var is founded in the list, then the copy of the var is the element of the list; if not, then a new copy is made and the is var added to the list

Overrides:
copy in class Term

isGT

public boolean isGT(Term t)
Description copied from class: Term
is term greater than term t?

Overrides:
isGT in class Term

isEQU

public boolean isEQU(Term t)
Description copied from class: Term
is term equal to term t?

Overrides:
isEQU in class Term

toString

public java.lang.String toString()
gets string representation of the var.

if var bounded, then write Name/Term; else if there is no name, write underscore character

Overrides:
toString in class Term

toStringFlattened

public java.lang.String toStringFlattened()
get the flat string representation of a variable.

if var bounded, then get the string representation of the Term bound