示例#1
0
 public SExpression length() {
   long l = 0;
   SExpression s = this;
   while (!s.isAtom()) {
     l++;
     s = s.cdr();
   }
   return new SExpression(BigInteger.valueOf(l));
 }
示例#2
0
 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(')');
 }
示例#3
0
 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;
   }
 }
示例#4
0
 public SExpression cons(SExpression t) {
   if (t.isAtom() && t != Atom.NIL) {
     return this;
   }
   return new SExpression(this, t);
 }