Class Atom
- java.lang.Object
-
- org.jpl7.Term
-
- org.jpl7.Atom
-
public class Atom extends Term
Atom is a specialised Term, representing a Prolog atom with the same name. An Atom is constructed with a String parameter (its name, unquoted), which cannot thereafter be changed.Atom a = new Atom("hello");
An Atom can be used (and re-used) as an argument of Compound Terms. Two Atom instances are equal (by equals()) iff they are of the same type and have equal values.
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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Term[]
args()
The arguments of this Term.java.lang.String
atomType()
boolean
equals(java.lang.Object obj)
Two Atoms are equal if they are identical (same object) or their respective names and blobTypes are equalboolean
hasFunctor(java.lang.String name, int arity)
Tests whether this Compound's functor has (String) 'name' and 'arity'.boolean
isListNil()
whether this Term denotes (syntax-specifically) an empty listjava.lang.String
name()
the name (unquoted) of this Compoundjava.lang.String
toString()
an Atom's name is quoted if it is not a simple identifier.int
type()
returns the type of this term, as "Prolog.ATOM"java.lang.String
typeName()
returns the name of the type of this term, as "Atom"-
Methods inherited from class org.jpl7.Term
arg, arity, bigValue, doubleValue, floatValue, hasFunctor, hasFunctor, hasFunctor, intValue, isAtom, isBig, isBigInteger, isCompound, isFloat, isInteger, isJFalse, isJNull, isJRef, isJTrue, isJVoid, isListPair, isVariable, jrefToObject, listLength, longValue, object, objectToJRef, putParams, putTerm, ref, toString, toTermArray
-
-
-
-
Constructor Detail
-
Atom
public Atom(java.lang.String name)
This constructs a "text" Atom, and is equivalent tonew Atom(name, "text")
- Parameters:
name
- the Atom's name (unquoted)- Throws:
JPLException
- if name is null
-
Atom
public Atom(java.lang.String name, java.lang.String type)
- Parameters:
name
- the Atom's name (unquoted)type
- the required Atom type, e.g. "text" or "string"- Throws:
JPLException
- if name or type is null, or if type is "jref"
-
-
Method Detail
-
args
public 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
-
atomType
public final java.lang.String atomType()
-
equals
public final boolean equals(java.lang.Object obj)
Two Atoms are equal if they are identical (same object) or their respective names and blobTypes are equal- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the Object to compare (not necessarily another Atom)- Returns:
- true if the Object satisfies the above condition
-
hasFunctor
public final boolean hasFunctor(java.lang.String name, int arity)
Tests whether this Compound's functor has (String) 'name' and 'arity'.- Overrides:
hasFunctor
in classTerm
- Parameters:
name
- a possible name for the functor of a termarity
- an arity 0+- Returns:
- whether this Compound's functor has (String) 'name' and 'arity'
-
isListNil
public final boolean isListNil()
whether this Term denotes (syntax-specifically) an empty list- Overrides:
isListNil
in classTerm
- Returns:
- whether this Term denotes an empty list within the current syntax ("traditional" or "modern").
- See Also:
JPL.getSyntax()
-
name
public final java.lang.String name()
the name (unquoted) of this Compound
-
toString
public java.lang.String toString()
an Atom's name is quoted if it is not a simple identifier.- Overrides:
toString
in classjava.lang.Object
- Returns:
- string representation of an Atom
-
type
public final int type()
returns the type of this term, as "Prolog.ATOM"
-
-