public SExpression length() { long l = 0; SExpression s = this; while (!s.isAtom()) { l++; s = s.cdr(); } return new SExpression(BigInteger.valueOf(l)); }
void toS(SExpression s) { if (s.isAtom() && !s.printValue.equals("")) { sb.append(s.printValue); return; } sb.append('('); while (!s.isAtom()) { toS(s.car); s = s.cdr; if (!s.isAtom()) { sb.append(' '); } } sb.append(')'); }
public boolean equals(Object o) { if (o instanceof SExpression) { SExpression s = (SExpression) o; if (number && s.number) { return nValue.equals(s.nValue); } if (number || s.number) { return false; } if (atom && s.atom) { return this == s; } if (atom || s.atom) { return false; } return car.equals(s.car) && cdr.equals(s.cdr); } else { return false; } }
public SExpression cons(SExpression t) { if (t.isAtom() && t != Atom.NIL) { return this; } return new SExpression(this, t); }