-
Notifications
You must be signed in to change notification settings - Fork 1
/
cadr.c
482 lines (416 loc) · 10.5 KB
/
cadr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/* This file is generated by gencadr.txr */
/* Copyright 2009-2024
* Kaz Kylheku <kaz@kylheku.com>
* Vancouver, Canada
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <limits.h>
#include "config.h"
#include "lib.h"
#include "eval.h"
#include "stream.h"
#include "autoload.h"
#include "txr.h"
#include "cadr.h"
val caar(val cons)
{
return car(car(cons));
}
val cadr(val cons)
{
return car(cdr(cons));
}
val cdar(val cons)
{
return cdr(car(cons));
}
val cddr(val cons)
{
return cdr(cdr(cons));
}
val caaar(val cons)
{
return car(car(car(cons)));
}
val caadr(val cons)
{
return car(car(cdr(cons)));
}
val cadar(val cons)
{
return car(cdr(car(cons)));
}
val caddr(val cons)
{
return car(cdr(cdr(cons)));
}
val cdaar(val cons)
{
return cdr(car(car(cons)));
}
val cdadr(val cons)
{
return cdr(car(cdr(cons)));
}
val cddar(val cons)
{
return cdr(cdr(car(cons)));
}
val cdddr(val cons)
{
return cdr(cdr(cdr(cons)));
}
val caaaar(val cons)
{
return car(car(car(car(cons))));
}
val caaadr(val cons)
{
return car(car(car(cdr(cons))));
}
val caadar(val cons)
{
return car(car(cdr(car(cons))));
}
val caaddr(val cons)
{
return car(car(cdr(cdr(cons))));
}
val cadaar(val cons)
{
return car(cdr(car(car(cons))));
}
val cadadr(val cons)
{
return car(cdr(car(cdr(cons))));
}
val caddar(val cons)
{
return car(cdr(cdr(car(cons))));
}
val cadddr(val cons)
{
return car(cdr(cdr(cdr(cons))));
}
val cdaaar(val cons)
{
return cdr(car(car(car(cons))));
}
val cdaadr(val cons)
{
return cdr(car(car(cdr(cons))));
}
val cdadar(val cons)
{
return cdr(car(cdr(car(cons))));
}
val cdaddr(val cons)
{
return cdr(car(cdr(cdr(cons))));
}
val cddaar(val cons)
{
return cdr(cdr(car(car(cons))));
}
val cddadr(val cons)
{
return cdr(cdr(car(cdr(cons))));
}
val cdddar(val cons)
{
return cdr(cdr(cdr(car(cons))));
}
val cddddr(val cons)
{
return cdr(cdr(cdr(cdr(cons))));
}
val caaaaar(val cons)
{
return car(car(car(car(car(cons)))));
}
val caaaadr(val cons)
{
return car(car(car(car(cdr(cons)))));
}
val caaadar(val cons)
{
return car(car(car(cdr(car(cons)))));
}
val caaaddr(val cons)
{
return car(car(car(cdr(cdr(cons)))));
}
val caadaar(val cons)
{
return car(car(cdr(car(car(cons)))));
}
val caadadr(val cons)
{
return car(car(cdr(car(cdr(cons)))));
}
val caaddar(val cons)
{
return car(car(cdr(cdr(car(cons)))));
}
val caadddr(val cons)
{
return car(car(cdr(cdr(cdr(cons)))));
}
val cadaaar(val cons)
{
return car(cdr(car(car(car(cons)))));
}
val cadaadr(val cons)
{
return car(cdr(car(car(cdr(cons)))));
}
val cadadar(val cons)
{
return car(cdr(car(cdr(car(cons)))));
}
val cadaddr(val cons)
{
return car(cdr(car(cdr(cdr(cons)))));
}
val caddaar(val cons)
{
return car(cdr(cdr(car(car(cons)))));
}
val caddadr(val cons)
{
return car(cdr(cdr(car(cdr(cons)))));
}
val cadddar(val cons)
{
return car(cdr(cdr(cdr(car(cons)))));
}
val caddddr(val cons)
{
return car(cdr(cdr(cdr(cdr(cons)))));
}
val cdaaaar(val cons)
{
return cdr(car(car(car(car(cons)))));
}
val cdaaadr(val cons)
{
return cdr(car(car(car(cdr(cons)))));
}
val cdaadar(val cons)
{
return cdr(car(car(cdr(car(cons)))));
}
val cdaaddr(val cons)
{
return cdr(car(car(cdr(cdr(cons)))));
}
val cdadaar(val cons)
{
return cdr(car(cdr(car(car(cons)))));
}
val cdadadr(val cons)
{
return cdr(car(cdr(car(cdr(cons)))));
}
val cdaddar(val cons)
{
return cdr(car(cdr(cdr(car(cons)))));
}
val cdadddr(val cons)
{
return cdr(car(cdr(cdr(cdr(cons)))));
}
val cddaaar(val cons)
{
return cdr(cdr(car(car(car(cons)))));
}
val cddaadr(val cons)
{
return cdr(cdr(car(car(cdr(cons)))));
}
val cddadar(val cons)
{
return cdr(cdr(car(cdr(car(cons)))));
}
val cddaddr(val cons)
{
return cdr(cdr(car(cdr(cdr(cons)))));
}
val cdddaar(val cons)
{
return cdr(cdr(cdr(car(car(cons)))));
}
val cdddadr(val cons)
{
return cdr(cdr(cdr(car(cdr(cons)))));
}
val cddddar(val cons)
{
return cdr(cdr(cdr(cdr(car(cons)))));
}
val cdddddr(val cons)
{
return cdr(cdr(cdr(cdr(cdr(cons)))));
}
static val cadr_register(void)
{
reg_fun(intern(lit("caar"), user_package), func_n1(caar));
reg_fun(intern(lit("cadr"), user_package), func_n1(cadr));
reg_fun(intern(lit("cdar"), user_package), func_n1(cdar));
reg_fun(intern(lit("cddr"), user_package), func_n1(cddr));
reg_fun(intern(lit("caaar"), user_package), func_n1(caaar));
reg_fun(intern(lit("caadr"), user_package), func_n1(caadr));
reg_fun(intern(lit("cadar"), user_package), func_n1(cadar));
reg_fun(intern(lit("caddr"), user_package), func_n1(caddr));
reg_fun(intern(lit("cdaar"), user_package), func_n1(cdaar));
reg_fun(intern(lit("cdadr"), user_package), func_n1(cdadr));
reg_fun(intern(lit("cddar"), user_package), func_n1(cddar));
reg_fun(intern(lit("cdddr"), user_package), func_n1(cdddr));
reg_fun(intern(lit("caaaar"), user_package), func_n1(caaaar));
reg_fun(intern(lit("caaadr"), user_package), func_n1(caaadr));
reg_fun(intern(lit("caadar"), user_package), func_n1(caadar));
reg_fun(intern(lit("caaddr"), user_package), func_n1(caaddr));
reg_fun(intern(lit("cadaar"), user_package), func_n1(cadaar));
reg_fun(intern(lit("cadadr"), user_package), func_n1(cadadr));
reg_fun(intern(lit("caddar"), user_package), func_n1(caddar));
reg_fun(intern(lit("cadddr"), user_package), func_n1(cadddr));
reg_fun(intern(lit("cdaaar"), user_package), func_n1(cdaaar));
reg_fun(intern(lit("cdaadr"), user_package), func_n1(cdaadr));
reg_fun(intern(lit("cdadar"), user_package), func_n1(cdadar));
reg_fun(intern(lit("cdaddr"), user_package), func_n1(cdaddr));
reg_fun(intern(lit("cddaar"), user_package), func_n1(cddaar));
reg_fun(intern(lit("cddadr"), user_package), func_n1(cddadr));
reg_fun(intern(lit("cdddar"), user_package), func_n1(cdddar));
reg_fun(intern(lit("cddddr"), user_package), func_n1(cddddr));
reg_fun(intern(lit("caaaaar"), user_package), func_n1(caaaaar));
reg_fun(intern(lit("caaaadr"), user_package), func_n1(caaaadr));
reg_fun(intern(lit("caaadar"), user_package), func_n1(caaadar));
reg_fun(intern(lit("caaaddr"), user_package), func_n1(caaaddr));
reg_fun(intern(lit("caadaar"), user_package), func_n1(caadaar));
reg_fun(intern(lit("caadadr"), user_package), func_n1(caadadr));
reg_fun(intern(lit("caaddar"), user_package), func_n1(caaddar));
reg_fun(intern(lit("caadddr"), user_package), func_n1(caadddr));
reg_fun(intern(lit("cadaaar"), user_package), func_n1(cadaaar));
reg_fun(intern(lit("cadaadr"), user_package), func_n1(cadaadr));
reg_fun(intern(lit("cadadar"), user_package), func_n1(cadadar));
reg_fun(intern(lit("cadaddr"), user_package), func_n1(cadaddr));
reg_fun(intern(lit("caddaar"), user_package), func_n1(caddaar));
reg_fun(intern(lit("caddadr"), user_package), func_n1(caddadr));
reg_fun(intern(lit("cadddar"), user_package), func_n1(cadddar));
reg_fun(intern(lit("caddddr"), user_package), func_n1(caddddr));
reg_fun(intern(lit("cdaaaar"), user_package), func_n1(cdaaaar));
reg_fun(intern(lit("cdaaadr"), user_package), func_n1(cdaaadr));
reg_fun(intern(lit("cdaadar"), user_package), func_n1(cdaadar));
reg_fun(intern(lit("cdaaddr"), user_package), func_n1(cdaaddr));
reg_fun(intern(lit("cdadaar"), user_package), func_n1(cdadaar));
reg_fun(intern(lit("cdadadr"), user_package), func_n1(cdadadr));
reg_fun(intern(lit("cdaddar"), user_package), func_n1(cdaddar));
reg_fun(intern(lit("cdadddr"), user_package), func_n1(cdadddr));
reg_fun(intern(lit("cddaaar"), user_package), func_n1(cddaaar));
reg_fun(intern(lit("cddaadr"), user_package), func_n1(cddaadr));
reg_fun(intern(lit("cddadar"), user_package), func_n1(cddadar));
reg_fun(intern(lit("cddaddr"), user_package), func_n1(cddaddr));
reg_fun(intern(lit("cdddaar"), user_package), func_n1(cdddaar));
reg_fun(intern(lit("cdddadr"), user_package), func_n1(cdddadr));
reg_fun(intern(lit("cddddar"), user_package), func_n1(cddddar));
reg_fun(intern(lit("cdddddr"), user_package), func_n1(cdddddr));
load(scat2(stdlib_path, lit("cadr")));
return nil;
}
static val cadr_set_entries(val fun)
{
val name[] = {
lit("caar"),
lit("cadr"),
lit("cdar"),
lit("cddr"),
lit("caaar"),
lit("caadr"),
lit("cadar"),
lit("caddr"),
lit("cdaar"),
lit("cdadr"),
lit("cddar"),
lit("cdddr"),
lit("caaaar"),
lit("caaadr"),
lit("caadar"),
lit("caaddr"),
lit("cadaar"),
lit("cadadr"),
lit("caddar"),
lit("cadddr"),
lit("cdaaar"),
lit("cdaadr"),
lit("cdadar"),
lit("cdaddr"),
lit("cddaar"),
lit("cddadr"),
lit("cdddar"),
lit("cddddr"),
lit("caaaaar"),
lit("caaaadr"),
lit("caaadar"),
lit("caaaddr"),
lit("caadaar"),
lit("caadadr"),
lit("caaddar"),
lit("caadddr"),
lit("cadaaar"),
lit("cadaadr"),
lit("cadadar"),
lit("cadaddr"),
lit("caddaar"),
lit("caddadr"),
lit("cadddar"),
lit("caddddr"),
lit("cdaaaar"),
lit("cdaaadr"),
lit("cdaadar"),
lit("cdaaddr"),
lit("cdadaar"),
lit("cdadadr"),
lit("cdaddar"),
lit("cdadddr"),
lit("cddaaar"),
lit("cddaadr"),
lit("cddadar"),
lit("cddaddr"),
lit("cdddaar"),
lit("cdddadr"),
lit("cddddar"),
lit("cdddddr"),
nil
};
autoload_set(al_fun, name, fun);
return nil;
}
void cadr_init(void)
{
autoload_reg(cadr_register, cadr_set_entries);
}