Class Symbol

java.lang.Object
  extended bySymbol
All Implemented Interfaces:
Unifiable

public class Symbol
extends java.lang.Object
implements Unifiable

Symbols are a basic datatype in Lisp. There should be only one Symbol with a given name accessible, so most applications should use intern() rather than creating Symbols using the constructor.


Field Summary
(package private) static int gencounter
          Counter used by gensym().
(package private)  java.lang.String name
          The name of this symbol (what Lisp calls the ``print-name'').
(package private) static java.util.HashMap symbolTable
          Private static (class) field holding name->Symbol mapping.
 
Constructor Summary
Symbol(java.lang.String name)
          Create a new symbol with the given name.
 
Method Summary
 Unifiable copyWithBindings(BindingSet bindings)
          Returns this Symbol itself, since applying bindings to a Symbol has no effect and symbols don't need to be copied.
static Symbol gensym(java.lang.String name)
          Return a new uniquely-named Symbol whose name starts with the given String.
static Symbol gensym(Symbol other)
          Return a new uniquely-named Symbol whose name starts with the name of the given Symbol.
static Symbol intern(java.lang.String name)
          Main method for getting a Symbol given a name; creates the Symbol if necessary.
 java.lang.String toString()
          Returns the printable representation of this Symbol (i.e., its name).
 boolean unifyWith(Unifiable other, BindingSet bindings)
          Try to unify this Symbol with another Unifiable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

java.lang.String name
The name of this symbol (what Lisp calls the ``print-name'').


symbolTable

static java.util.HashMap symbolTable
Private static (class) field holding name->Symbol mapping.


gencounter

static int gencounter
Counter used by gensym().

Constructor Detail

Symbol

public Symbol(java.lang.String name)
Create a new symbol with the given name. You almost certainly want use intern() rather than calling this constructor directly.

Method Detail

toString

public java.lang.String toString()
Returns the printable representation of this Symbol (i.e., its name).


intern

public static Symbol intern(java.lang.String name)
Main method for getting a Symbol given a name; creates the Symbol if necessary. This method could be extended to support Lisp's notion of ``packages'' if anyone cared. Note that Symbols are not case-sensitive (on purpose).


gensym

public static Symbol gensym(java.lang.String name)
Return a new uniquely-named Symbol whose name starts with the given String.


gensym

public static Symbol gensym(Symbol other)
Return a new uniquely-named Symbol whose name starts with the name of the given Symbol.


unifyWith

public boolean unifyWith(Unifiable other,
                         BindingSet bindings)
Try to unify this Symbol with another Unifiable. A Symbol unifies only with itself.

Specified by:
unifyWith in interface Unifiable

copyWithBindings

public Unifiable copyWithBindings(BindingSet bindings)
Returns this Symbol itself, since applying bindings to a Symbol has no effect and symbols don't need to be copied.

Specified by:
copyWithBindings in interface Unifiable