Kernel Prolog with Fluent based Builtins

tarau.jinni
Class Term

java.lang.Object
  |
  +--tarau.jinni.Term
Direct Known Subclasses:
Nonvar, Var

public abstract class Term
extends java.lang.Object
implements java.lang.Cloneable

Top element of the Prolog term hierarchy. Describes a simple or compound ter like: X,a,13,f(X,s(X)),[a,s(X),b,c], a:-b,c(X,X),d, etc.


Field Summary
static int CONST
           
static int INT
           
static int JAVA
           
static int REAL
           
static int VAR
           
 
Constructor Summary
Term()
           
 
Method Summary
(package private)  Term action(Term that)
          Identity action.
(package private) abstract  boolean bind_to(Term that, Trail trail)
           
(package private) static java.lang.String charsToString(Nonvar Cs)
          Converts a list of character codes to a String.
 Term copy()
          Returns a copy of a term with variables standardized apart (`fresh variables').
(package private) abstract  boolean eq(Term that)
           
(package private)  int exec()
           
protected  int exec(Prog p)
          Executed when a builtin is called.
static Term fromString(java.lang.String s)
           
abstract  int getArity()
          returns or fakes an arity for all subtypes
 java.lang.String getKey()
          Returns a string key used based on the string name of the term.
 boolean isBuiltin()
           
(package private)  boolean isClause()
           
 boolean matches(Term that)
          Tests if this term unifies with that.
 Term matching_copy(Term that)
          Returns a copy of the result if the unification of this and that.
 Term numbervars()
          Replaces variables with uppercase constants named `V1', 'V2', etc.
 java.lang.String pprint()
          Prints out a term to a String with variables named in order V1, V2,....
 java.lang.String pprint(boolean replaceAnonymous)
           
(package private)  Term reaction(Term agent)
          Defines the reaction to an agent recursing over the structure of a term.
protected  Term ref()
          Dereferences if necessary.
(package private) static Nonvar stringToChars(java.lang.String s)
           
 Nonvar toChars()
           
 Clause toClause()
           
(package private)  Term token()
           
 java.lang.Object toObject()
          Java Object wrapper.
(package private)  Term toTerm()
           
 java.lang.String toUnquoted()
           
protected  void undo()
           
(package private) abstract  boolean unify_to(Term that, Trail trail)
          Unify dereferenced
protected  boolean unify(Term that, Trail trail)
          Dereference and unify_to
 Term varsOf()
          Returns '[]'(V1,V2,..Vn) where Vi is a variable occuring in this Term
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

JAVA

public static final int JAVA

REAL

public static final int REAL

INT

public static final int INT

VAR

public static final int VAR

CONST

public static final int CONST
Constructor Detail

Term

public Term()
Method Detail

getArity

public abstract int getArity()
returns or fakes an arity for all subtypes

ref

protected Term ref()
Dereferences if necessary. This should be synchronized otherwise vicious non-reentrancy problems may occur in the presence of GC and heavy multi-threading!!!

bind_to

abstract boolean bind_to(Term that,
                         Trail trail)

unify_to

abstract boolean unify_to(Term that,
                          Trail trail)
Unify dereferenced

unify

protected final boolean unify(Term that,
                              Trail trail)
Dereference and unify_to

undo

protected void undo()

eq

abstract boolean eq(Term that)

token

Term token()

toTerm

Term toTerm()

toClause

public Clause toClause()

isClause

boolean isClause()

fromString

public static Term fromString(java.lang.String s)

matches

public boolean matches(Term that)
Tests if this term unifies with that. Bindings are trailed and undone after the test. This should be used with the shared term as this and the new term as that. Synchronization makes sure that side effects on the shared term are not interfering, i.e as in: SHARED.matches(NONSHARED,trail).

matching_copy

public Term matching_copy(Term that)
Returns a copy of the result if the unification of this and that. Side effects on this and that are undone using trailing of bindings.. Synchronization happens over this, not over that. Make sure it is used as SHARED.matching_copy(NONSHARED,trail).

reaction

Term reaction(Term agent)
Defines the reaction to an agent recursing over the structure of a term. This is passed to the agent and the result of the action is returned. Through overriding, for instance, a Fun term will provide the recursion over its arguments, by applying the action to each of them.
See Also:
Fun

action

Term action(Term that)
Identity action.

copy

public Term copy()
Returns a copy of a term with variables standardized apart (`fresh variables').

varsOf

public Term varsOf()
Returns '[]'(V1,V2,..Vn) where Vi is a variable occuring in this Term

numbervars

public Term numbervars()
Replaces variables with uppercase constants named `V1', 'V2', etc. to be read back as variables.

pprint

public java.lang.String pprint()
Prints out a term to a String with variables named in order V1, V2,....

pprint

public java.lang.String pprint(boolean replaceAnonymous)

toUnquoted

public java.lang.String toUnquoted()

getKey

public java.lang.String getKey()
Returns a string key used based on the string name of the term. Note that the key for a clause AL-B,C. is the key insted of ':-'.

toObject

public java.lang.Object toObject()
Java Object wrapper. In particular, it is used to wrap a Thread to hide it inside a Prolog data object.

exec

final int exec()

exec

protected int exec(Prog p)
Executed when a builtin is called. Needs to be overriden. Returns a run-time warning if this is forgotten.

stringToChars

static final Nonvar stringToChars(java.lang.String s)

toChars

public Nonvar toChars()

charsToString

static java.lang.String charsToString(Nonvar Cs)
Converts a list of character codes to a String.

isBuiltin

public boolean isBuiltin()

Kernel Prolog with Fluent based Builtins