public class Variable extends Term
A jpl.Variable instance is equivalent to a variable in a fragment of Prolog source text: it is *not* a "live" variable within a Prolog stack or heap. A corresponding Prolog variable is created only upon opening a Query whose goal refers to a Variable (and then only temporarily).
Copyright (C) 1998 Fred Dushin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Modifier and Type | Field and Description |
---|---|
protected int |
index |
java.lang.String |
name
the name of this Variable (may be changed as of April 2020)
|
protected term_t |
term_
defined between Query.open() and Query.get2()
|
Constructor and Description |
---|
Variable()
Create a new don't tell Variable with new sequential name of the form "_261".
|
Variable(java.lang.String name)
Create a new Variable with 'name' (which must not be null or ""), and may
one day be constrained to comply with traditional Prolog syntax.
|
Modifier and Type | Method and Description |
---|---|
Term[] |
args()
The arguments of this Term.
|
int |
arity()
returns, as an int, the arity of a Term
|
boolean |
equals(java.lang.Object o)
A Variable is equal to another if their names are the same
Totally lexical textual interpretation of vars, not related to bindings
Anonymous var _ is always different (including to itsef)
|
protected void |
getSubst(java.util.Map<java.lang.String,Term> varnames_to_Terms,
java.util.Map<term_t,Variable> vars_to_Vars)
This can be used to get the **current** solution binding of the Variable instance.
|
boolean |
hasFunctor(java.math.BigInteger value,
int arity)
Tests whether this Term's functor has 'name' and 'arity'
|
boolean |
hasFunctor(double value,
int arity)
Tests whether this Term's functor has 'name' and 'arity'
|
boolean |
hasFunctor(long value,
int arity)
Tests whether this Term's functor has 'name' and 'arity'
|
boolean |
hasFunctor(java.lang.String name,
int arity)
Whether this Term's functor has 'name' and 'arity' (c.f.
|
int |
hashCode() |
java.lang.String |
name()
the lexical name of this Variable
|
protected void |
put(java.util.Map<java.lang.String,term_t> varnames_to_vars,
term_t term)
To put a Variable, we must check whether a (non-anonymous) variable with
the same name has already been put in the Term.
|
void |
setName(java.lang.String name) |
java.lang.String |
toString()
Returns a Prolog source text representation of this Variable
|
int |
type()
returns the type of this subclass of Term, i.e.
|
java.lang.String |
typeName()
returns the typeName of this subclass of Term, i.e.
|
arg, atomListToStringArray, atomType, bigValue, doubleValue, floatValue, getSubsts, getTerm, getTerm, intArrayArrayToList, intArrayToList, intValue, isAtom, isAtomOfNameType, isBig, isBigInteger, isCompound, isFloat, isInteger, isJFalse, isJNull, isJRef, isJTrue, isJVoid, isList, isList, isListNil, isListPair, isVariable, jrefToObject, listLength, listLength, listToTermArray, listToTermArray, longValue, object, objectToJRef, put, putParams, putParams, putParams1, putParams2, putTerm, putTerms, ref, stringArrayToList, termArrayToList, textParamsToTerm, textToTerm, toString, toTermArray
protected transient int index
public java.lang.String name
protected transient term_t term_
public Variable()
public Variable(java.lang.String name)
name
- the source name of this Variablepublic final Term[] args()
Term
Note that a SWI Prolog 7.x compound term can have zero arguments.
This method returns an empty Term[] from an Atom, Float, Integer or JRef, approximating the behaviour of SWI Prolog's =../2
public int arity()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- The Object to compare.public int hashCode()
hashCode
in class java.lang.Object
protected final void getSubst(java.util.Map<java.lang.String,Term> varnames_to_Terms, java.util.Map<term_t,Variable> vars_to_Vars)
public boolean hasFunctor(java.math.BigInteger value, int arity)
Term
For Float and Integer, mimics behaviour of SWI Prolog's functor/3
hasFunctor
in class Term
value
- a possible name for the functor of a termarity
- an arity 0+public boolean hasFunctor(java.lang.String name, int arity)
Term
hasFunctor
in class Term
name
- a possible name for the functor of a termarity
- an arity 0+public boolean hasFunctor(long value, int arity)
Term
For Float and Integer, mimics behaviour of SWI Prolog's functor/3
hasFunctor
in class Term
value
- a possible name for the functor of a termarity
- an arity 0+public boolean hasFunctor(double value, int arity)
Term
For Float and Integer, mimics behaviour of SWI Prolog's functor/3
hasFunctor
in class Term
value
- a possible name for the functor of a termarity
- an arity 0+public final java.lang.String name()
protected final void put(java.util.Map<java.lang.String,term_t> varnames_to_vars, term_t term)
public java.lang.String toString()
toString
in class java.lang.Object
public final int type()