[armedbear-cvs] r12590 - trunk/abcl/src/org/armedbear/lisp

Ville Voutilainen vvoutilainen at common-lisp.net
Sat Apr 10 18:38:04 UTC 2010


Author: vvoutilainen
Date: Sat Apr 10 14:38:03 2010
New Revision: 12590

Log:
Make nthcdr and NTH(LispObject) final.


Modified:
   trunk/abcl/src/org/armedbear/lisp/Cons.java
   trunk/abcl/src/org/armedbear/lisp/LispObject.java
   trunk/abcl/src/org/armedbear/lisp/Nil.java

Modified: trunk/abcl/src/org/armedbear/lisp/Cons.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Cons.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Cons.java	Sat Apr 10 14:38:03 2010
@@ -134,22 +134,6 @@
   }
 
   @Override
-  public LispObject nthcdr(int n)
-  {
-    if (n < 0)
-      return type_error(Fixnum.getInstance(n),
-                             list(Symbol.INTEGER, Fixnum.ZERO));
-    LispObject result = this;
-    for (int i = n; i-- > 0;)
-      {
-        result = result.cdr();
-        if (result == NIL)
-          break;
-      }
-    return result;
-  }
-
-  @Override
   public final int sxhash()
   {
     return computeHash(this, 4);
@@ -260,40 +244,6 @@
   }
 
   @Override
-  public LispObject NTH(LispObject arg)
-  {
-    int index;
-    if (arg instanceof Fixnum)
-      {
-        index = ((Fixnum)arg).value;
-      }
-    else
-        {
-        if (arg instanceof Bignum)
-          {
-            // FIXME (when machines have enough memory for it to matter)
-            if (arg.minusp())
-              return type_error(arg, Symbol.UNSIGNED_BYTE);
-            return NIL;
-          }
-        return type_error(arg, Symbol.UNSIGNED_BYTE);
-      }
-    if (index < 0)
-      type_error(arg, Symbol.UNSIGNED_BYTE);
-    int i = 0;
-    LispObject obj = this;
-    while (true)
-      {
-        if (i == index)
-          return obj.car();
-        obj = obj.cdr();
-        if (obj == NIL)
-          return NIL;
-        ++i;
-      }
-  }
-
-  @Override
   public LispObject elt(int index)
   {
     if (index < 0)

Modified: trunk/abcl/src/org/armedbear/lisp/LispObject.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/LispObject.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/LispObject.java	Sat Apr 10 14:38:03 2010
@@ -222,11 +222,22 @@
         return NIL;
   }
 
-  public LispObject nthcdr(int n)
+  public final LispObject nthcdr(int n)
   {
     if (n < 0)
       return type_error(Fixnum.getInstance(n),
                              list(Symbol.INTEGER, Fixnum.ZERO));
+    if (this instanceof Cons) {
+      LispObject result = this;
+      for (int i = n; i-- > 0;) {
+          result = result.cdr();
+          if (result == NIL)
+              break;
+      }
+      return result;
+    } else if (this instanceof Nil) {
+      return NIL;
+    }
     return type_error(this, Symbol.LIST);
   }
 
@@ -482,9 +493,9 @@
     return type_error(this, Symbol.LIST);
   }
 
-  public LispObject NTH(LispObject arg)
+  public final LispObject NTH(LispObject arg)
   {
-    return type_error(this, Symbol.LIST);
+    return NTH(Fixnum.getValue(arg));
   }
 
   public LispObject elt(int index)

Modified: trunk/abcl/src/org/armedbear/lisp/Nil.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Nil.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Nil.java	Sat Apr 10 14:38:03 2010
@@ -107,15 +107,6 @@
     }
 
     @Override
-    public LispObject nthcdr(int n)
-    {
-        if (n < 0)
-            return type_error(Fixnum.getInstance(n),
-                                   list(Symbol.INTEGER, Fixnum.ZERO));
-        return this;
-    }
-
-    @Override
     public int length()
     {
         return 0;
@@ -131,23 +122,6 @@
     }
 
     @Override
-    public LispObject NTH(LispObject arg)
-    {
-        int index;
-                if (arg instanceof Fixnum) {
-                        index = ((Fixnum) arg).value;
-                } else if (arg instanceof Bignum) {
-                        if (arg.minusp())
-                                return error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
-                        return NIL;
-                } else
-                        return error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
-                if (index < 0)
-                        error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
-                return NIL;
-    }
-
-    @Override
     public LispObject elt(int index)
     {
         return error(new TypeError("ELT: invalid index " + index + " for " + this + "."));




More information about the armedbear-cvs mailing list