source: branches/0.17.x/abcl/src/org/armedbear/lisp/Nil.java

Last change on this file was 12254, checked in by ehuelsmann, 16 years ago

Remove 'throws ConditionThrowable?' method annotations:

it's an unchecked exception now, so no need to declare it thrown.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1/*
2 * Nil.java
3 *
4 * Copyright (C) 2002-2006 Peter Graves
5 * $Id: Nil.java 12254 2009-11-06 20:07:54Z ehuelsmann $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36public final class Nil extends Symbol
37{
38    final static Nil NIL = new Nil(PACKAGE_CL);
39
40    public Nil(Package pkg)
41    {
42        super("NIL", pkg);
43        pkg.addSymbol(this);
44        initializeConstant(this);
45    }
46
47    @Override
48    public LispObject typeOf()
49    {
50        return Symbol.NULL;
51    }
52
53    @Override
54    public LispObject classOf()
55    {
56        return BuiltInClass.NULL;
57    }
58
59    @Override
60    public LispObject getDescription()
61    {
62        return new SimpleString("The symbol NIL");
63    }
64
65    @Override
66    public boolean getBooleanValue()
67    {
68        return false;
69    }
70
71    @Override
72    public LispObject typep(LispObject typeSpecifier)
73    {
74        if (typeSpecifier == Symbol.NULL)
75            return T;
76        if (typeSpecifier == Symbol.LIST)
77            return T;
78        if (typeSpecifier == Symbol.SEQUENCE)
79            return T;
80        if (typeSpecifier == Symbol.SYMBOL)
81            return T;
82        if (typeSpecifier == Symbol.BOOLEAN)
83            return T;
84        if (typeSpecifier == BuiltInClass.NULL)
85            return T;
86        if (typeSpecifier == BuiltInClass.LIST)
87            return T;
88        if (typeSpecifier == BuiltInClass.SEQUENCE)
89            return T;
90        if (typeSpecifier == BuiltInClass.SYMBOL)
91            return T;
92        return super.typep(typeSpecifier);
93    }
94
95    @Override
96    public boolean constantp()
97    {
98        return true;
99    }
100
101    @Override
102    public final LispObject getSymbolValue()
103    {
104        return this;
105    }
106
107    @Override
108    public LispObject car()
109    {
110        return this;
111    }
112
113    @Override
114    public LispObject cdr()
115    {
116        return this;
117    }
118
119    @Override
120    public final LispObject cadr()
121    {
122        return this;
123    }
124
125    @Override
126    public final LispObject cddr()
127    {
128        return this;
129    }
130
131    @Override
132    public final LispObject caddr()
133    {
134        return this;
135    }
136
137    @Override
138    public LispObject nthcdr(int n)
139    {
140        if (n < 0)
141            return type_error(Fixnum.getInstance(n),
142                                   list(Symbol.INTEGER, Fixnum.ZERO));
143        return this;
144    }
145
146    @Override
147    public int length()
148    {
149        return 0;
150    }
151
152    @Override
153    public LispObject push(LispObject obj)
154    {
155        return new Cons(obj);
156    }
157
158    @Override
159    public LispObject NTH(int index)
160    {
161        if (index < 0)
162            error(new TypeError(String.valueOf(index) +
163                                 " is not of type UNSIGNED-BYTE."));
164        return NIL;
165    }
166
167    @Override
168    public LispObject NTH(LispObject arg)
169    {
170        int index;
171                if (arg instanceof Fixnum) {
172                        index = ((Fixnum) arg).value;
173                } else if (arg instanceof Bignum) {
174                        if (arg.minusp())
175                                return error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
176                        return NIL;
177                } else
178                        return error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
179                if (index < 0)
180                        error(new TypeError(arg, Symbol.UNSIGNED_BYTE));
181                return NIL;
182    }
183
184    @Override
185    public LispObject elt(int index)
186    {
187        return error(new TypeError("ELT: invalid index " + index + " for " + this + "."));
188    }
189
190    @Override
191    public LispObject reverse()
192    {
193        return this;
194    }
195
196    @Override
197    public LispObject nreverse()
198    {
199        return this;
200    }
201
202    @Override
203    public LispObject[] copyToArray()
204    {
205        return new LispObject[0];
206    }
207
208    @Override
209    public boolean listp()
210    {
211        return true;
212    }
213
214    @Override
215    public LispObject LISTP()
216    {
217        return T;
218    }
219
220    @Override
221    public boolean endp()
222    {
223        return true;
224    }
225
226    @Override
227    public LispObject ENDP()
228    {
229        return T;
230    }
231
232    @Override
233    public LispObject NOT()
234    {
235        return T;
236    }
237
238    @Override
239    public final LispObject getSymbolFunction()
240    {
241        return null;
242    }
243
244    @Override
245    public String toString()
246    {
247        if (Symbol.PRINT_READABLY.symbolValueNoThrow() != NIL)
248            return "|COMMON-LISP|::|NIL|";
249        return "NIL";
250    }
251}
Note: See TracBrowser for help on using the repository browser.