Class Variable
- java.lang.Object
-
- org.jpl7.Term
-
- org.jpl7.Variable
-
public class Variable extends Term
This class supports Java representations of Prolog variables.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) 2004 Paul SingletonCopyright (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:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
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.
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
name
the name of this Variable
-
Constructor Summary
Constructors Constructor Description Variable()
Create a new 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Term[]
args()
The arguments of this Term.int
arity()
returns, as an int, the arity of a Termboolean
equals(java.lang.Object obj)
A Variable is equal to another if their names are the same and they are not anonymous.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.boolean
hasFunctor(java.math.BigInteger value, int arity)
Tests whether this Term's functor has 'name' and 'arity'java.lang.String
name()
the lexical name of this Variablejava.lang.String
toString()
Returns a Prolog source text representation of this Variableint
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.-
Methods inherited from class org.jpl7.Term
arg, atomType, bigValue, doubleValue, floatValue, intValue, isAtom, isBig, isBigInteger, isCompound, isFloat, isInteger, isJFalse, isJNull, isJRef, isJTrue, isJVoid, isListNil, isListPair, isVariable, jrefToObject, listLength, longValue, object, objectToJRef, putParams, putTerm, ref, toString, toTermArray
-
-
-
-
Constructor Detail
-
Variable
public Variable()
Create a new Variable with new sequential name of the form "_261".
-
Variable
public 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.- Parameters:
name
- the source name of this Variable
-
-
Method Detail
-
args
public final Term[] args()
Description copied from class:Term
The arguments of this 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
-
arity
public int arity()
returns, as an int, the arity of a Term
-
equals
public final boolean equals(java.lang.Object obj)
A Variable is equal to another if their names are the same and they are not anonymous.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- The Object to compare.- Returns:
- true if the Object is a Variable and the above condition apply.
-
hasFunctor
public boolean hasFunctor(java.math.BigInteger value, int arity)
Description copied from class:Term
Tests whether this Term's functor has 'name' and 'arity'For Float and Integer, mimics behaviour of SWI Prolog's functor/3
- Overrides:
hasFunctor
in classTerm
- Parameters:
value
- a possible name for the functor of a termarity
- an arity 0+- Returns:
- whether this Term's functor has 'name' and 'arity'
-
hasFunctor
public boolean hasFunctor(java.lang.String name, int arity)
Description copied from class:Term
Whether this Term's functor has 'name' and 'arity' (c.f. behaviour of SWI Prolog's functor/3)- Overrides:
hasFunctor
in classTerm
- Parameters:
name
- a possible name for the functor of a termarity
- an arity 0+- Returns:
- whether this Term's functor has 'name' and 'arity'
-
hasFunctor
public boolean hasFunctor(long value, int arity)
Description copied from class:Term
Tests whether this Term's functor has 'name' and 'arity'For Float and Integer, mimics behaviour of SWI Prolog's functor/3
- Overrides:
hasFunctor
in classTerm
- Parameters:
value
- a possible name for the functor of a termarity
- an arity 0+- Returns:
- whether this Term's functor has 'name' and 'arity'
-
hasFunctor
public boolean hasFunctor(double value, int arity)
Description copied from class:Term
Tests whether this Term's functor has 'name' and 'arity'For Float and Integer, mimics behaviour of SWI Prolog's functor/3
- Overrides:
hasFunctor
in classTerm
- Parameters:
value
- a possible name for the functor of a termarity
- an arity 0+- Returns:
- whether this Term's functor has 'name' and 'arity'
-
name
public final java.lang.String name()
the lexical name of this Variable
-
toString
public java.lang.String toString()
Returns a Prolog source text representation of this Variable- Overrides:
toString
in classjava.lang.Object
- Returns:
- a Prolog source text representation of this Variable
-
type
public final int type()
returns the type of this subclass of Term, i.e. Prolog.VARIABLE
-
-