/* Class representing atoms in D in Jones, Chapter 2 Written by: Kim Bruce, 9/16/2002 */ public class Atom implements D { private String value; // value of atom // Create atom with value val public Atom(String val) { value = val; } // create new list with other as head and this as tail public D cons(D other) { return new Composite(other,this); } // return head of this public D hd(){ return D.nil; } // return tail of this public D tl(){ return D.nil; } // return true iff this equals other public boolean booleq(D other){ return (other instanceof Atom && ((Atom)other).value.equals(value)); } // return dTrue if this equals other and dFalse otherwise public D eq(D other){ if (booleq(other)) return D.dTrue; else return D.dFalse; } // return string representation of atom public String toString() { return value; } public boolean isList() { return value.equals("nil"); } public String asList() { if (isList()) return "()"; else return "error: not a list"; } }