Changeset 12590


Ignore:
Timestamp:
04/10/10 18:38:03 (14 years ago)
Author:
vvoutilainen
Message:

Make nthcdr and NTH(LispObject) final.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Cons.java

    r12589 r12590  
    135135
    136136  @Override
    137   public LispObject nthcdr(int n)
    138   {
    139     if (n < 0)
    140       return type_error(Fixnum.getInstance(n),
    141                              list(Symbol.INTEGER, Fixnum.ZERO));
    142     LispObject result = this;
    143     for (int i = n; i-- > 0;)
    144       {
    145         result = result.cdr();
    146         if (result == NIL)
    147           break;
    148       }
    149     return result;
    150   }
    151 
    152   @Override
    153137  public final int sxhash()
    154138  {
     
    247231    if (index < 0)
    248232      type_error(Fixnum.getInstance(index), Symbol.UNSIGNED_BYTE);
    249     int i = 0;
    250     LispObject obj = this;
    251     while (true)
    252       {
    253         if (i == index)
    254           return obj.car();
    255         obj = obj.cdr();
    256         if (obj == NIL)
    257           return NIL;
    258         ++i;
    259       }
    260   }
    261 
    262   @Override
    263   public LispObject NTH(LispObject arg)
    264   {
    265     int index;
    266     if (arg instanceof Fixnum)
    267       {
    268         index = ((Fixnum)arg).value;
    269       }
    270     else
    271         {
    272         if (arg instanceof Bignum)
    273           {
    274             // FIXME (when machines have enough memory for it to matter)
    275             if (arg.minusp())
    276               return type_error(arg, Symbol.UNSIGNED_BYTE);
    277             return NIL;
    278           }
    279         return type_error(arg, Symbol.UNSIGNED_BYTE);
    280       }
    281     if (index < 0)
    282       type_error(arg, Symbol.UNSIGNED_BYTE);
    283233    int i = 0;
    284234    LispObject obj = this;
  • trunk/abcl/src/org/armedbear/lisp/LispObject.java

    r12589 r12590  
    223223  }
    224224
    225   public LispObject nthcdr(int n)
     225  public final LispObject nthcdr(int n)
    226226  {
    227227    if (n < 0)
    228228      return type_error(Fixnum.getInstance(n),
    229229                             list(Symbol.INTEGER, Fixnum.ZERO));
     230    if (this instanceof Cons) {
     231      LispObject result = this;
     232      for (int i = n; i-- > 0;) {
     233          result = result.cdr();
     234          if (result == NIL)
     235              break;
     236      }
     237      return result;
     238    } else if (this instanceof Nil) {
     239      return NIL;
     240    }
    230241    return type_error(this, Symbol.LIST);
    231242  }
     
    483494  }
    484495
    485   public LispObject NTH(LispObject arg)
    486   {
    487     return type_error(this, Symbol.LIST);
     496  public final LispObject NTH(LispObject arg)
     497  {
     498    return NTH(Fixnum.getValue(arg));
    488499  }
    489500
  • trunk/abcl/src/org/armedbear/lisp/Nil.java

    r12589 r12590  
    108108
    109109    @Override
    110     public LispObject nthcdr(int n)
    111     {
    112         if (n < 0)
    113             return type_error(Fixnum.getInstance(n),
    114                                    list(Symbol.INTEGER, Fixnum.ZERO));
    115         return this;
    116     }
    117 
    118     @Override
    119110    public int length()
    120111    {
     
    129120                                 " is not of type UNSIGNED-BYTE."));
    130121        return NIL;
    131     }
    132 
    133     @Override
    134     public LispObject NTH(LispObject arg)
    135     {
    136         int index;
    137                 if (arg instanceof Fixnum) {
    138                         index = ((Fixnum) arg).value;
    139                 } else if (arg instanceof Bignum) {
    140                         if (arg.minusp())
    141                                 return error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
    142                         return NIL;
    143                 } else
    144                         return error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
    145                 if (index < 0)
    146                         error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
    147                 return NIL;
    148122    }
    149123
Note: See TracChangeset for help on using the changeset viewer.