Jalog 1.4
java.lang.Object io.github.JalogTeam.jalog.Pro_Term
public class Pro_Term
All data and programs are represented as Pro_Term
objects. Every
Pro_Term
object has a pointer to a Pro_TermData
object
that contains the associated data.
A Pro_Term
object representing a program clause points to an object of type Pro_TermData_Compound
that contains the head and the body of the clause.
A Pro_Term
object representing an open variable either points to an object of type Pro_TermData_Unified
that points to another open Pro_Term
object or does not point to any data.
A Pro_Term
object representing a bound variable
either points to an object of type Pro_TermData_Unified
that points to another bound Pro_Term
object or points to an object of type Pro_TermData
that contains the data.
The usual way to create a term is to use one of the methods whose name starts with "m_
". The usual way to assign a value to an existing open term is to use one of the unify
methods.
According to Prolog rules a value of a term can be changed only if it is open or in backtrack.
Field Summary | |
---|---|
static Pro_Term |
EMPTY_LIST
The empty list. |
public long |
Id
Unique identification number of this object. |
static long |
lastId
To assign unique identification number for each term. Updated by constructors. |
static long |
lastPrintId
To assign unique display number for each displayed open term. Updated by toString method. |
public long |
printId
Unique display number of this object. |
Constructor Summary | |
---|---|
Pro_Term()
Constructs an open Pro_Term object. |
|
Pro_Term(Pro_TermData data)
Constructs a unified or bound Pro_Term object. |
Method Summary | |
---|---|
void
|
clearData()
Removes data and makes this term open. |
void
|
compval(Pro_Term term)
Calculates the value of the expression in term and stores the result in this object.
|
Pro_Term
|
copy()
Returns an independent copy of this term. |
Pro_Term
|
copy(Hashtable variable_map)
Returns an independent copy this of term using variable_map .
|
static long
|
eval_integer(Pro_Term p)
Calculates the value of the expression in p and returns it if it is an integer otherwise 0.
|
Pro_TermData
|
getData()
Returns the data associated to this term, or null if this term is open.
|
Pro_Term
|
getRealNode()
If this object is linked to another Pro_Term object (as a result of unification) then finds the actual node otherwise returns this object.
|
String
|
getType()
Returns the type of this term. |
String
|
image()
Returns human readable string representation of this term. |
static Pro_Term
|
m_char(char iniVal)
Creates a new Pro_Term object with a character value.
|
static Pro_Term
|
m_compound(String iniName, Pro_Term[] iniSubterm)
Creates a new Pro_Term object with a compound value.
|
static Pro_Term
|
m_integer(long iniVal)
Creates a new Pro_Term object with an integer value.
|
static Pro_Term
|
m_list(Pro_Term[] iniVal, Pro_Term tail)
Creates a new Pro_Term object with a list value.
|
static Pro_Term
|
m_open()
Creates a new open Pro_Term object.
|
static Pro_Term
|
m_real(double iniVal)
Creates a new Pro_Term object with a real value.
|
static Pro_Term
|
m_string(String iniVal)
Creates a new Pro_Term object with a string value.
|
static Pro_Term
|
m_string_concat(Pro_TermData_String left,
Pro_TermData_String right)
Creates a new Pro_Term object with a string value.
|
static Pro_Term
|
m_string_substring(Pro_TermData_String base_string,
long req_start, long req_len)
Creates a new Pro_Term object with a string value.
|
static Pro_Term
|
m_unified(Pro_Term iniVal)
Creates a new Pro_Term object unified with another.
|
boolean
|
match(Pro_Term pn2)
Checks wheter this term can be unified with another term but does not unify them. |
String
|
toString()
Returns Jalog syntax representation of this term. |
boolean
|
unify(Pro_Term pn2, Pro_Trail pBack)
Unifies this term with another term. |
boolean
|
unify(Pro_Term pn2, Pro_Trail pBack, Pro_TrailMark Mark)
Unifies this term with another term. |
Field Detail |
---|
public static Pro_Term EMPTY_LIST
public long Id
public static long lastId
Id
assigned to a term by a constructor. Before creating a term a
constructor increases this by one.
public static long lastPrintId
printId
assigned to an open term by a toString
method. The purpose of
this is to assign small integer printId
for each separate open
variable to be displayed.
public long printId
Constructor Detail |
---|
public Pro_Term()
Pro_Term
object.
public Pro_Term(Pro_TermData data)
Pro_Term
object.
data
- the data to be associated to this
term.Method Detail |
---|
public void clearData()
void compval(Pro_Term term)
term
and stores the result in this
object. If there is no calculable expression value of this object is set to the same as the value of term
. If term
is open this
and term
are unified.
This method should only be used if this
term is open because according to Prolog rules a value of a term can be changed only if it is open or in backtrack.
public Pro_Term copy()
public Pro_Term copy(Hashtable variable_map)
variable_map
. Hashtable is used to map repeated open terms to repeated open terms. Hashtable is updated for new open terms. Used in database asserting and fetching.
variable_map
- contains open variable mapping for this term.
variable_map
.
public static long eval_integer(Pro_Term p)
p
and returns it if it is an integer, otherwise returns 0. Useful for indexing.
p
- the expression as a Pro_Term
.
public Pro_TermData getData()
null
if this term is open. If this term is unified to another term the data of the other term is returned, or null if the other term is open.
null
if this term is open.
public Pro_Term getRealNode()
Pro_Term
object (as a result of unification) then finds the actual node otherwise returns this object.
public String getType()
Jalog
public String image()
write
.
public static Pro_Term m_char(char iniVal)
Pro_Term
object with a character value.
iniVal
- value for the new term.
public static Pro_Term m_compound(String iniName, Pro_Term[] iniSubterm)
Pro_Term
object with a compound value. If the iniSubterm
array is empty the type of the created term is SYMBOL
, otherwise COMPOUND
.
iniName
- functor.
iniSubterm
- subterms in an array.
public static Pro_Term m_integer(long iniVal)
Pro_Term
object with an integer value.
iniVal
- value for the new term.
public static Pro_Term m_list(Pro_Term[] iniVal, Pro_Term tail)
Pro_Term
object with a list value.
iniVal
- list items in an array.
tail
- tail of the list. Can be the Pro_Term.EMPTY_LIST
if all items are listed in iniVal
. For an open list this must be an open term.
public static Pro_Term m_open()
Pro_Term
object.
public static Pro_Term m_real(double iniVal)
Pro_Term
object with a real value.
iniVal
- value for the new term.
public static Pro_Term m_string(String iniVal)
Pro_Term
object with a string value.
iniVal
- value for the new term.
public static Pro_Term m_string_concat(Pro_TermData_String left, Pro_TermData_String right)
Pro_Term
object with a string value.
left
- left part for the new term.
right
- right part for the new term.
public static Pro_Term m_string_substring(Pro_TermData_String base_string, long req_start, long req_len)
Pro_Term
object with a string value. The resulting string contains a part of the base_string
. First req_start
characters are not included. If req_len
is less than the remaining length of the base_string
then req_len
characters are included, otherwise the rest of the base_string
is included. If req_start
is greater than the length of the base_string
then an empty string is created.
base_string
- a string containing the required result as a substring.
req_start
- number of characters skipped from the beginning of the base_string
.
req_len
- number of characters to be included in the result.
public static Pro_Term m_unified(Pro_Term iniVal)
Pro_Term
object unified with iniVal
.
iniVal
- the term to be unified with.
public boolean match(Pro_Term pn2)
pn2
- compared term.
true
if the paramater can be unified with this
, false
othewise.
public String toString()
public boolean unify(Pro_Term pn2, Pro_Trail pBack)
this
term and the argument term so that they are equivalent. Open subterms are replaced with corresponding subterms in the other term, or computed values of corresponding subterms if they can be computed. If the corresponding subterm is open, the subterms are unified. If unification does not succeed neither this
nor pn2
is updated.
pn2
- compared term.
pBack
- use Pred.trail
.
true
if unification succeeded, false
otherwise.
public boolean unify(Pro_Term pn2, Pro_Trail pBack, Pro_TrailMark Mark)
this
term and the argument term so that they are equivalent. Open subterms are replaced with corresponding subterms in the other term, or computed values of corresponding subterms if they can be computed. If the corresponding subterm is open, the subterms are unified. If unification does not succeed neither this
nor pn2
is updated.Mark
is not null
then before unification sets Mark.marked
to point to the top of the trail.
pn2
- compared term.
pBack
- use Pred.trail
.
Mark
- trail mark for backtracking.
true
if unification succeeded, false
otherwise.