Add name() to Term API

This can help when matching a StructureTerm with isStructure().
diff --git a/src/lang/ClosureTerm.java b/src/lang/ClosureTerm.java
index 7287fb5..8a21788 100644
--- a/src/lang/ClosureTerm.java
+++ b/src/lang/ClosureTerm.java
@@ -30,6 +30,8 @@
 
     public String toQuotedString() { return toString(); }
 
+    public String name() { return ""; }
+
     /* Object */
     /**
      * Checks <em>term equality</em> of two terms.
diff --git a/src/lang/DoubleTerm.java b/src/lang/DoubleTerm.java
index 337f5dd..f387213 100644
--- a/src/lang/DoubleTerm.java
+++ b/src/lang/DoubleTerm.java
@@ -38,6 +38,8 @@
 	return this.val == ((DoubleTerm)t).value();
     }
 
+    public String name() { return ""; }
+
     /** 
      * @return the <code>boolean</code> whose value is
      * <code>convertible(Double.class, type)</code>.
@@ -45,8 +47,6 @@
      */
     public boolean convertible(Class type) { return convertible(Double.class, type); }
 
-    //    protected Term copy(Prolog engine) { return new DoubleTerm(val); }
-
     /** 
      * Returns a <code>java.lang.Double</code> corresponds to this <code>DoubleTerm</code>
      * according to <em>Prolog Cafe interoperability with Java</em>.
diff --git a/src/lang/IntegerTerm.java b/src/lang/IntegerTerm.java
index f79899f..8aebbd8 100644
--- a/src/lang/IntegerTerm.java
+++ b/src/lang/IntegerTerm.java
@@ -42,7 +42,7 @@
      */
     public boolean convertible(Class type) { return convertible(Integer.class, type); }
 
-    //    protected Term copy(Prolog engine) { return new IntegerTerm(val); }
+    public String name() { return ""; }
 
     /** 
      * Returns a <code>java.lang.Integer</code> corresponds to this <code>IntegerTerm</code>
diff --git a/src/lang/JavaObjectTerm.java b/src/lang/JavaObjectTerm.java
index cedb708..eb5d782 100644
--- a/src/lang/JavaObjectTerm.java
+++ b/src/lang/JavaObjectTerm.java
@@ -15,28 +15,25 @@
  */
 public class JavaObjectTerm extends Term {
     /** Holds a java object that this <code>JavaObjectTerm</code> wraps. */
-    protected Object obj = null;
-
-    /** Holds a <code>java.lang.Class</code> of object wrapped by this <code>JavaObjectTerm</code>. */
-    protected Class clazz = null;
+    protected Object obj;
 
     /** Constructs a new Prolog java-term that wraps the argument object. */
     public JavaObjectTerm(Object _obj) { 
-	if (_obj != null)
-	    setObject(_obj);
+	obj   = _obj;
     }
 
     /** Sets the argument object to this <code>JavaObjectTerm</code>. */
     public void setObject(Object _obj) {
 	obj   = _obj;
-	clazz = _obj.getClass();
     }
 
     /** Returns the object wrapped by this <code>JavaObjectTerm</code>. */
     public Object  object() { return obj; }
 
     /** Returns a <code>java.lang.Class</code> of object wrapped by this <code>JavaObjectTerm</code>. */
-    public Class   getClazz() { return clazz; }
+    public Class   getClazz() { return obj.getClass(); }
+
+    public String name() { return ""; }
 
     public String  toQuotedString() { return toString(); }
 
@@ -52,11 +49,11 @@
     /** 
      * Check whether the wrapped object is convertible with the given Java class type.
      * @return the <code>boolean</code> whose value is
-     * <code>convertible(clazz, type)</code>.
-     * @see #clazz
+     * <code>convertible(getClazz(), type)</code>.
+     * @see #getClazz()
      * @see Term#convertible(Class, Class)
      */
-    public boolean convertible(Class type) { return convertible(clazz, type); }
+    public boolean convertible(Class type) { return convertible(obj.getClass(), type); }
 
     /** 
      * Returns the object wrapped by this <code>JavaObjectTerm</code>.
@@ -89,7 +86,8 @@
 
     /** Returns a string representation of this <code>JavaObjectTerm</code>. */
     public String toString() {
-	return clazz.getName() + "(" + hashCode() + ")";
+	return obj.getClass().getName()
+      + "(0x" + Integer.toHexString(hashCode()) + ")";
     }
 
     /* Comparable */
diff --git a/src/lang/ListTerm.java b/src/lang/ListTerm.java
index 4cb4ae5..b8d51a2 100644
--- a/src/lang/ListTerm.java
+++ b/src/lang/ListTerm.java
@@ -109,6 +109,8 @@
 	return true;
     }
 
+    public String name() { return SYM_DOT.name(); }
+
     /** Returns the length of this <code>ListTerm</code>. */
     public int length() {
 	int count = 0;
diff --git a/src/lang/Term.java b/src/lang/Term.java
index 9d823e1..cfcd732 100644
--- a/src/lang/Term.java
+++ b/src/lang/Term.java
@@ -102,6 +102,9 @@
      */
     public final boolean isClosure() { return this instanceof ClosureTerm; }
 
+    /** @return the name of this Term, if {@link #isStructure()}. */
+    public abstract String name();
+
     /** 
      * Check whether this object is convertible with the given Java class type.
      * @param type the Java class type to compare with.
diff --git a/src/lang/VariableTerm.java b/src/lang/VariableTerm.java
index 65da789..db9f56e 100644
--- a/src/lang/VariableTerm.java
+++ b/src/lang/VariableTerm.java
@@ -22,7 +22,7 @@
      */
     public VariableTerm() {
 	val = this;
-    	timeStamp = Long.MIN_VALUE;
+    timeStamp = Long.MIN_VALUE;
     }
 
     /** Constructs a new logical variable so that
@@ -37,7 +37,7 @@
     }
 
     /** Returns a string representation of this object.*/
-    protected String name() { return "_" + Integer.toHexString(hashCode()).toUpperCase(); }
+    protected String variableName() { return "_" + Integer.toHexString(hashCode()).toUpperCase(); }
 
     /* Term */
     /** 
@@ -130,6 +130,12 @@
 	return false;
     }
 
+    public String name() {
+    if (val == this)
+      return "";
+    return val.dereference().name();
+    }
+
     /** 
      * Returns <code>this</code> if this variable is unbound.
      * Otherwise, returns a Java object that corresponds to the dereferenced term:
@@ -152,7 +158,7 @@
     public String toQuotedString() {
 	if (val != this)
 	    return val.toQuotedString();
-	return name();
+	return variableName();
     }
 
     /* Object */
@@ -184,7 +190,7 @@
     public String toString() {
 	if (val != this)
 	    return val.toString();
-	return name();
+	return variableName();
     }
 
     /* Undoable */