예제 #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);
 }