1 | /* |
---|
2 | * cxr.java |
---|
3 | * |
---|
4 | * Copyright (C) 2003-2005 Peter Graves |
---|
5 | * $Id: cxr.java 12472 2010-02-14 13:32:12Z vvoutilainen $ |
---|
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 | |
---|
34 | package org.armedbear.lisp; |
---|
35 | |
---|
36 | import static org.armedbear.lisp.Lisp.*; |
---|
37 | |
---|
38 | public final class cxr { |
---|
39 | // ### set-car |
---|
40 | private static final Primitive SET_CAR = new pf_set_car(); |
---|
41 | private static final class pf_set_car extends Primitive { |
---|
42 | pf_set_car() { |
---|
43 | super("set-car", PACKAGE_SYS, true); |
---|
44 | } |
---|
45 | |
---|
46 | @Override |
---|
47 | public LispObject execute(LispObject first, LispObject second) |
---|
48 | |
---|
49 | { |
---|
50 | first.setCar(second); |
---|
51 | return second; |
---|
52 | } |
---|
53 | }; |
---|
54 | |
---|
55 | // ### set-cdr |
---|
56 | private static final Primitive SET_CDR = new pf_set_cdr(); |
---|
57 | private static final class pf_set_cdr extends Primitive { |
---|
58 | pf_set_cdr() { |
---|
59 | super("set-cdr", PACKAGE_SYS, true); |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public LispObject execute(LispObject first, LispObject second) |
---|
64 | |
---|
65 | { |
---|
66 | first.setCdr(second); |
---|
67 | return second; |
---|
68 | } |
---|
69 | }; |
---|
70 | |
---|
71 | // ### car |
---|
72 | private static final Primitive CAR = new pf_car(); |
---|
73 | private static final class pf_car extends Primitive { |
---|
74 | pf_car() { |
---|
75 | super(Symbol.CAR, "list"); |
---|
76 | } |
---|
77 | |
---|
78 | @Override |
---|
79 | public LispObject execute(LispObject arg) { |
---|
80 | return arg.car(); |
---|
81 | } |
---|
82 | }; |
---|
83 | |
---|
84 | // ### cdr |
---|
85 | private static final Primitive CDR = new pf_cdr(); |
---|
86 | private static final class pf_cdr extends Primitive { |
---|
87 | pf_cdr() { |
---|
88 | super(Symbol.CDR, "list"); |
---|
89 | } |
---|
90 | |
---|
91 | @Override |
---|
92 | public LispObject execute(LispObject arg) { |
---|
93 | return arg.cdr(); |
---|
94 | } |
---|
95 | }; |
---|
96 | |
---|
97 | // ### caar |
---|
98 | private static final Primitive CAAR = new pf_caar(); |
---|
99 | private static final class pf_caar extends Primitive { |
---|
100 | pf_caar() { |
---|
101 | super(Symbol.CAAR, "list"); |
---|
102 | } |
---|
103 | |
---|
104 | @Override |
---|
105 | public LispObject execute(LispObject arg) { |
---|
106 | return arg.car().car(); |
---|
107 | } |
---|
108 | }; |
---|
109 | |
---|
110 | // ### cadr |
---|
111 | private static final Primitive CADR = new pf_cadr(); |
---|
112 | private static final class pf_cadr extends Primitive { |
---|
113 | pf_cadr() { |
---|
114 | super(Symbol.CADR, "list"); |
---|
115 | } |
---|
116 | |
---|
117 | @Override |
---|
118 | public LispObject execute(LispObject arg) { |
---|
119 | return arg.cadr(); |
---|
120 | } |
---|
121 | }; |
---|
122 | |
---|
123 | // ### cdar |
---|
124 | private static final Primitive CDAR = new pf_cdar(); |
---|
125 | private static final class pf_cdar extends Primitive { |
---|
126 | pf_cdar() { |
---|
127 | super(Symbol.CDAR, "list"); |
---|
128 | } |
---|
129 | |
---|
130 | @Override |
---|
131 | public LispObject execute(LispObject arg) { |
---|
132 | return arg.car().cdr(); |
---|
133 | } |
---|
134 | }; |
---|
135 | |
---|
136 | // ### cddr |
---|
137 | private static final Primitive CDDR = new pf_cddr(); |
---|
138 | private static final class pf_cddr extends Primitive { |
---|
139 | pf_cddr() { |
---|
140 | super(Symbol.CDDR, "list"); |
---|
141 | } |
---|
142 | |
---|
143 | @Override |
---|
144 | public LispObject execute(LispObject arg) { |
---|
145 | return arg.cdr().cdr(); |
---|
146 | } |
---|
147 | }; |
---|
148 | |
---|
149 | // ### caddr |
---|
150 | private static final Primitive CADDR = new pf_caddr(); |
---|
151 | private static final class pf_caddr extends Primitive { |
---|
152 | pf_caddr() { |
---|
153 | super(Symbol.CADDR, "list"); |
---|
154 | } |
---|
155 | |
---|
156 | @Override |
---|
157 | public LispObject execute(LispObject arg) { |
---|
158 | return arg.caddr(); |
---|
159 | } |
---|
160 | }; |
---|
161 | |
---|
162 | // ### caadr |
---|
163 | private static final Primitive CAADR = new pf_caadr(); |
---|
164 | private static final class pf_caadr extends Primitive { |
---|
165 | pf_caadr() { |
---|
166 | super(Symbol.CAADR, "list"); |
---|
167 | } |
---|
168 | |
---|
169 | @Override |
---|
170 | public LispObject execute(LispObject arg) { |
---|
171 | return arg.cdr().car().car(); |
---|
172 | } |
---|
173 | }; |
---|
174 | |
---|
175 | // ### caaar |
---|
176 | private static final Primitive CAAAR = new pf_caaar(); |
---|
177 | private static final class pf_caaar extends Primitive { |
---|
178 | pf_caaar() { |
---|
179 | super(Symbol.CAAAR, "list"); |
---|
180 | } |
---|
181 | |
---|
182 | @Override |
---|
183 | public LispObject execute(LispObject arg) { |
---|
184 | return arg.car().car().car(); |
---|
185 | } |
---|
186 | }; |
---|
187 | |
---|
188 | // ### cdaar |
---|
189 | private static final Primitive CDAAR = new pf_cdaar(); |
---|
190 | private static final class pf_cdaar extends Primitive { |
---|
191 | pf_cdaar() { |
---|
192 | super(Symbol.CDAAR, "list"); |
---|
193 | } |
---|
194 | |
---|
195 | @Override |
---|
196 | public LispObject execute(LispObject arg) { |
---|
197 | return arg.car().car().cdr(); |
---|
198 | } |
---|
199 | }; |
---|
200 | |
---|
201 | // ### cddar |
---|
202 | private static final Primitive CDDAR = new pf_cddar(); |
---|
203 | private static final class pf_cddar extends Primitive { |
---|
204 | pf_cddar() { |
---|
205 | super(Symbol.CDDAR, "list"); |
---|
206 | } |
---|
207 | |
---|
208 | @Override |
---|
209 | public LispObject execute(LispObject arg) { |
---|
210 | return arg.car().cdr().cdr(); |
---|
211 | } |
---|
212 | }; |
---|
213 | |
---|
214 | // ### cdddr |
---|
215 | private static final Primitive CDDDR = new pf_cdddr(); |
---|
216 | private static final class pf_cdddr extends Primitive { |
---|
217 | pf_cdddr() { |
---|
218 | super(Symbol.CDDDR, "list"); |
---|
219 | } |
---|
220 | |
---|
221 | @Override |
---|
222 | public LispObject execute(LispObject arg) { |
---|
223 | return arg.cdr().cdr().cdr(); |
---|
224 | } |
---|
225 | }; |
---|
226 | |
---|
227 | // ### cadar |
---|
228 | private static final Primitive CADAR = new pf_cadar(); |
---|
229 | private static final class pf_cadar extends Primitive { |
---|
230 | pf_cadar() { |
---|
231 | super(Symbol.CADAR, "list"); |
---|
232 | } |
---|
233 | |
---|
234 | @Override |
---|
235 | public LispObject execute(LispObject arg) { |
---|
236 | return arg.car().cdr().car(); |
---|
237 | } |
---|
238 | }; |
---|
239 | |
---|
240 | // ### cdadr |
---|
241 | private static final Primitive CDADR = new pf_cdadr(); |
---|
242 | private static final class pf_cdadr extends Primitive { |
---|
243 | pf_cdadr() { |
---|
244 | super(Symbol.CDADR, "list"); |
---|
245 | } |
---|
246 | |
---|
247 | @Override |
---|
248 | public LispObject execute(LispObject arg) { |
---|
249 | return arg.cdr().car().cdr(); |
---|
250 | } |
---|
251 | }; |
---|
252 | |
---|
253 | // ### first |
---|
254 | private static final Primitive FIRST = new pf_first(); |
---|
255 | private static final class pf_first extends Primitive { |
---|
256 | pf_first() { |
---|
257 | super(Symbol.FIRST, "list"); |
---|
258 | } |
---|
259 | |
---|
260 | @Override |
---|
261 | public LispObject execute(LispObject arg) { |
---|
262 | return arg.car(); |
---|
263 | } |
---|
264 | }; |
---|
265 | |
---|
266 | // ### second |
---|
267 | private static final Primitive SECOND = new pf_second(); |
---|
268 | private static final class pf_second extends Primitive { |
---|
269 | pf_second() { |
---|
270 | super(Symbol.SECOND, "list"); |
---|
271 | } |
---|
272 | |
---|
273 | @Override |
---|
274 | public LispObject execute(LispObject arg) { |
---|
275 | return arg.cadr(); |
---|
276 | } |
---|
277 | }; |
---|
278 | |
---|
279 | // ### third |
---|
280 | private static final Primitive THIRD = new pf_third(); |
---|
281 | private static final class pf_third extends Primitive { |
---|
282 | pf_third() { |
---|
283 | super(Symbol.THIRD, "list"); |
---|
284 | } |
---|
285 | |
---|
286 | @Override |
---|
287 | public LispObject execute(LispObject arg) { |
---|
288 | return arg.caddr(); |
---|
289 | } |
---|
290 | }; |
---|
291 | |
---|
292 | // ### fourth |
---|
293 | private static final Primitive FOURTH = new pf_fourth(); |
---|
294 | private static final class pf_fourth extends Primitive { |
---|
295 | pf_fourth() { |
---|
296 | super(Symbol.FOURTH, "list"); |
---|
297 | } |
---|
298 | |
---|
299 | @Override |
---|
300 | public LispObject execute(LispObject arg) { |
---|
301 | return arg.cdr().cdr().cadr(); |
---|
302 | } |
---|
303 | }; |
---|
304 | |
---|
305 | // ### rest |
---|
306 | private static final Primitive REST = new pf_rest(); |
---|
307 | private static final class pf_rest extends Primitive { |
---|
308 | pf_rest() { |
---|
309 | super(Symbol.REST, "list"); |
---|
310 | } |
---|
311 | |
---|
312 | @Override |
---|
313 | public LispObject execute(LispObject arg) { |
---|
314 | return arg.cdr(); |
---|
315 | } |
---|
316 | }; |
---|
317 | } |
---|