Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* Copyright (C) 1995,1996 Free Software Foundation, Inc. |
2 | * | |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation; either version 2, or (at your option) | |
6 | * any later version. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this software; see the file COPYING. If not, write to | |
15 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
16 | * | |
17 | * As a special exception, the Free Software Foundation gives permission | |
18 | * for additional uses of the text contained in its release of GUILE. | |
19 | * | |
20 | * The exception is that, if you link the GUILE library with other files | |
21 | * to produce an executable, this does not by itself cause the | |
22 | * resulting executable to be covered by the GNU General Public License. | |
23 | * Your use of that executable is in no way restricted on account of | |
24 | * linking the GUILE library code into it. | |
25 | * | |
26 | * This exception does not however invalidate any other reasons why | |
27 | * the executable file might be covered by the GNU General Public License. | |
28 | * | |
29 | * This exception applies only to the code released by the | |
30 | * Free Software Foundation under the name GUILE. If you copy | |
31 | * code from other Free Software Foundation releases into a copy of | |
32 | * GUILE, as the General Public License permits, the exception does | |
33 | * not apply to the code that you add in this way. To avoid misleading | |
34 | * anyone as to the status of such modified files, you must delete | |
35 | * this exception notice from them. | |
36 | * | |
37 | * If you write modifications of your own for GUILE, it is your choice | |
38 | * whether to permit this exception to apply to your modifications. | |
39 | * If you do not wish that, delete this exception notice. | |
40 | */ | |
41 | \f | |
42 | #include <stdio.h> | |
43 | #include "_scm.h" | |
20e6290e JB |
44 | #include "eq.h" |
45 | #include "list.h" | |
46 | ||
47 | #include "alist.h" | |
0f2d19dd JB |
48 | |
49 | \f | |
50 | ||
51 | SCM_PROC(s_acons, "acons", 3, 0, 0, scm_acons); | |
52 | #ifdef __STDC__ | |
53 | SCM | |
54 | scm_acons (SCM w, SCM x, SCM y) | |
55 | #else | |
56 | SCM | |
57 | scm_acons (w, x, y) | |
58 | SCM w; | |
59 | SCM x; | |
60 | SCM y; | |
61 | #endif | |
62 | { | |
63 | register SCM z; | |
64 | SCM_NEWCELL (z); | |
65 | SCM_CAR (z) = w; | |
66 | SCM_CDR (z) = x; | |
67 | x = z; | |
68 | SCM_NEWCELL (z); | |
69 | SCM_CAR (z) = x; | |
70 | SCM_CDR (z) = y; | |
71 | return z; | |
72 | } | |
73 | ||
74 | \f | |
75 | ||
76 | SCM_PROC (s_sloppy_assq, "sloppy-assq", 2, 0, 0, scm_sloppy_assq); | |
77 | #ifdef __STDC__ | |
78 | SCM | |
79 | scm_sloppy_assq(SCM x, SCM alist) | |
80 | #else | |
81 | SCM | |
82 | scm_sloppy_assq(x, alist) | |
83 | SCM x; | |
84 | SCM alist; | |
85 | #endif | |
86 | { | |
87 | SCM tmp; | |
88 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) | |
89 | { | |
90 | if (SCM_CONSP(alist)) | |
91 | { | |
92 | tmp = SCM_CAR(alist); | |
93 | if (SCM_NIMP (tmp) && SCM_CONSP (tmp) && (SCM_CAR (tmp)==x)) | |
94 | return tmp; | |
95 | } | |
96 | } | |
97 | return SCM_BOOL_F; | |
98 | } | |
99 | ||
100 | ||
101 | ||
102 | SCM_PROC (s_sloppy_assv, "sloppy-assv", 2, 0, 0, scm_sloppy_assv); | |
103 | #ifdef __STDC__ | |
104 | SCM | |
105 | scm_sloppy_assv(SCM x, SCM alist) | |
106 | #else | |
107 | SCM | |
108 | scm_sloppy_assv(x, alist) | |
109 | SCM x; | |
110 | SCM alist; | |
111 | #endif | |
112 | { | |
113 | SCM tmp; | |
114 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) | |
115 | { | |
116 | if (SCM_CONSP(alist)) | |
117 | { | |
118 | tmp = SCM_CAR(alist); | |
119 | if ( SCM_NIMP (tmp) | |
120 | && SCM_CONSP (tmp) | |
121 | && SCM_NFALSEP (scm_eqv_p (SCM_CAR (tmp), x))) | |
122 | return tmp; | |
123 | } | |
124 | } | |
125 | return SCM_BOOL_F; | |
126 | } | |
127 | ||
128 | ||
129 | SCM_PROC (s_sloppy_assoc, "sloppy-assoc", 2, 0, 0, scm_sloppy_assoc); | |
130 | #ifdef __STDC__ | |
131 | SCM | |
132 | scm_sloppy_assoc(SCM x, SCM alist) | |
133 | #else | |
134 | SCM | |
135 | scm_sloppy_assoc(x, alist) | |
136 | SCM x; | |
137 | SCM alist; | |
138 | #endif | |
139 | { | |
140 | SCM tmp; | |
141 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) | |
142 | { | |
143 | if (SCM_CONSP(alist)) | |
144 | { | |
145 | tmp = SCM_CAR(alist); | |
146 | if ( SCM_NIMP (tmp) | |
147 | && SCM_CONSP (tmp) | |
148 | && SCM_NFALSEP (scm_equal_p (SCM_CAR (tmp), x))) | |
149 | return tmp; | |
150 | } | |
151 | } | |
152 | return SCM_BOOL_F; | |
153 | } | |
154 | ||
155 | ||
156 | \f | |
157 | ||
158 | SCM_PROC(s_assq, "assq", 2, 0, 0, scm_assq); | |
159 | #ifdef __STDC__ | |
160 | SCM | |
161 | scm_assq(SCM x, SCM alist) | |
162 | #else | |
163 | SCM | |
164 | scm_assq(x, alist) | |
165 | SCM x; | |
166 | SCM alist; | |
167 | #endif | |
168 | { | |
169 | SCM tmp; | |
170 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) { | |
171 | SCM_ASSERT(SCM_CONSP(alist), alist, SCM_ARG2, s_assq); | |
172 | tmp = SCM_CAR(alist); | |
173 | SCM_ASSERT(SCM_NIMP(tmp) && SCM_CONSP(tmp), alist, SCM_ARG2, s_assq); | |
174 | if (SCM_CAR(tmp)==x) return tmp; | |
175 | } | |
176 | SCM_ASSERT(SCM_NULLP(alist), alist, SCM_ARG2, s_assq); | |
177 | return SCM_BOOL_F; | |
178 | } | |
179 | ||
180 | ||
181 | SCM_PROC(s_assv, "assv", 2, 0, 0, scm_assv); | |
182 | #ifdef __STDC__ | |
183 | SCM | |
184 | scm_assv(SCM x, SCM alist) | |
185 | #else | |
186 | SCM | |
187 | scm_assv(x, alist) | |
188 | SCM x; | |
189 | SCM alist; | |
190 | #endif | |
191 | { | |
192 | SCM tmp; | |
193 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) { | |
194 | SCM_ASRTGO(SCM_CONSP(alist), badlst); | |
195 | tmp = SCM_CAR(alist); | |
196 | SCM_ASRTGO(SCM_NIMP(tmp) && SCM_CONSP(tmp), badlst); | |
197 | if SCM_NFALSEP(scm_eqv_p(SCM_CAR(tmp), x)) return tmp; | |
198 | } | |
199 | # ifndef RECKLESS | |
200 | if (!(SCM_NULLP(alist))) | |
201 | badlst: scm_wta(alist, (char *)SCM_ARG2, s_assv); | |
202 | # endif | |
203 | return SCM_BOOL_F; | |
204 | } | |
205 | ||
206 | ||
207 | SCM_PROC(s_assoc, "assoc", 2, 0, 0, scm_assoc); | |
208 | #ifdef __STDC__ | |
209 | SCM | |
210 | scm_assoc(SCM x, SCM alist) | |
211 | #else | |
212 | SCM | |
213 | scm_assoc(x, alist) | |
214 | SCM x; | |
215 | SCM alist; | |
216 | #endif | |
217 | { | |
218 | SCM tmp; | |
219 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) { | |
220 | SCM_ASSERT(SCM_CONSP(alist), alist, SCM_ARG2, s_assoc); | |
221 | tmp = SCM_CAR(alist); | |
222 | SCM_ASSERT(SCM_NIMP(tmp) && SCM_CONSP(tmp), alist, SCM_ARG2, s_assoc); | |
223 | if SCM_NFALSEP(scm_equal_p(SCM_CAR(tmp), x)) return tmp; | |
224 | } | |
225 | SCM_ASSERT(SCM_NULLP(alist), alist, SCM_ARG2, s_assoc); | |
226 | return SCM_BOOL_F; | |
227 | } | |
228 | ||
229 | ||
230 | \f | |
231 | ||
232 | SCM_PROC (s_assq_ref, "assq-ref", 2, 0, 0, scm_assq_ref); | |
233 | #ifdef __STDC__ | |
234 | SCM | |
235 | scm_assq_ref (SCM alist, SCM key) | |
236 | #else | |
237 | SCM | |
238 | scm_assq_ref (alist, key) | |
239 | SCM alist; | |
240 | SCM key; | |
241 | #endif | |
242 | { | |
243 | SCM handle; | |
244 | ||
245 | handle = scm_sloppy_assq (key, alist); | |
246 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
247 | { | |
248 | return SCM_CDR (handle); | |
249 | } | |
250 | return SCM_BOOL_F; | |
251 | } | |
252 | ||
253 | ||
254 | SCM_PROC (s_assv_ref, "assv-ref", 2, 0, 0, scm_assv_ref); | |
255 | #ifdef __STDC__ | |
256 | SCM | |
257 | scm_assv_ref (SCM alist, SCM key) | |
258 | #else | |
259 | SCM | |
260 | scm_assv_ref (alist, key) | |
261 | SCM alist; | |
262 | SCM key; | |
263 | #endif | |
264 | { | |
265 | SCM handle; | |
266 | ||
267 | handle = scm_sloppy_assv (key, alist); | |
268 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
269 | { | |
270 | return SCM_CDR (handle); | |
271 | } | |
272 | return SCM_BOOL_F; | |
273 | } | |
274 | ||
275 | ||
276 | SCM_PROC (s_assoc_ref, "assoc-ref", 2, 0, 0, scm_assoc_ref); | |
277 | #ifdef __STDC__ | |
278 | SCM | |
279 | scm_assoc_ref (SCM alist, SCM key) | |
280 | #else | |
281 | SCM | |
282 | scm_assoc_ref (alist, key) | |
283 | SCM alist; | |
284 | SCM key; | |
285 | #endif | |
286 | { | |
287 | SCM handle; | |
288 | ||
289 | handle = scm_sloppy_assoc (key, alist); | |
290 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
291 | { | |
292 | return SCM_CDR (handle); | |
293 | } | |
294 | return SCM_BOOL_F; | |
295 | } | |
296 | ||
297 | ||
298 | ||
299 | \f | |
300 | ||
301 | ||
302 | SCM_PROC (s_assq_set_x, "assq-set!", 3, 0, 0, scm_assq_set_x); | |
303 | #ifdef __STDC__ | |
304 | SCM | |
305 | scm_assq_set_x (SCM alist, SCM key, SCM val) | |
306 | #else | |
307 | SCM | |
308 | scm_assq_set_x (alist, key, val) | |
309 | SCM alist; | |
310 | SCM key; | |
311 | SCM val; | |
312 | #endif | |
313 | { | |
314 | SCM handle; | |
315 | ||
316 | handle = scm_sloppy_assq (key, alist); | |
317 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
318 | { | |
319 | SCM_SETCDR (handle, val); | |
320 | return alist; | |
321 | } | |
322 | else | |
323 | return scm_acons (key, val, alist); | |
324 | } | |
325 | ||
326 | SCM_PROC (s_assv_set_x, "assv-set!", 3, 0, 0, scm_assv_set_x); | |
327 | #ifdef __STDC__ | |
328 | SCM | |
329 | scm_assv_set_x (SCM alist, SCM key, SCM val) | |
330 | #else | |
331 | SCM | |
332 | scm_assv_set_x (alist, key, val) | |
333 | SCM alist; | |
334 | SCM key; | |
335 | SCM val; | |
336 | #endif | |
337 | { | |
338 | SCM handle; | |
339 | ||
340 | handle = scm_sloppy_assv (key, alist); | |
341 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
342 | { | |
343 | SCM_SETCDR (handle, val); | |
344 | return alist; | |
345 | } | |
346 | else | |
347 | return scm_acons (key, val, alist); | |
348 | } | |
349 | ||
350 | SCM_PROC (s_assoc_set_x, "assoc-set!", 3, 0, 0, scm_assoc_set_x); | |
351 | #ifdef __STDC__ | |
352 | SCM | |
353 | scm_assoc_set_x (SCM alist, SCM key, SCM val) | |
354 | #else | |
355 | SCM | |
356 | scm_assoc_set_x (alist, key, val) | |
357 | SCM alist; | |
358 | SCM key; | |
359 | SCM val; | |
360 | #endif | |
361 | { | |
362 | SCM handle; | |
363 | ||
364 | handle = scm_sloppy_assoc (key, alist); | |
365 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
366 | { | |
367 | SCM_SETCDR (handle, val); | |
368 | return alist; | |
369 | } | |
370 | else | |
371 | return scm_acons (key, val, alist); | |
372 | } | |
373 | ||
374 | ||
375 | \f | |
376 | ||
377 | SCM_PROC (s_assq_remove_x, "assq-remove!", 2, 0, 0, scm_assq_remove_x); | |
378 | #ifdef __STDC__ | |
379 | SCM | |
380 | scm_assq_remove_x (SCM alist, SCM key) | |
381 | #else | |
382 | SCM | |
383 | scm_assq_remove_x (alist, key) | |
384 | SCM alist; | |
385 | SCM key; | |
386 | #endif | |
387 | { | |
388 | SCM handle; | |
389 | ||
390 | handle = scm_sloppy_assq (key, alist); | |
391 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
392 | { | |
393 | return scm_delq_x (handle, alist); | |
394 | } | |
395 | else | |
396 | return alist; | |
397 | } | |
398 | ||
399 | ||
400 | SCM_PROC (s_assv_remove_x, "assv-remove!", 2, 0, 0, scm_assv_remove_x); | |
401 | #ifdef __STDC__ | |
402 | SCM | |
403 | scm_assv_remove_x (SCM alist, SCM key) | |
404 | #else | |
405 | SCM | |
406 | scm_assv_remove_x (alist, key) | |
407 | SCM alist; | |
408 | SCM key; | |
409 | #endif | |
410 | { | |
411 | SCM handle; | |
412 | ||
413 | handle = scm_sloppy_assv (key, alist); | |
414 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
415 | { | |
416 | return scm_delv_x (handle, alist); | |
417 | } | |
418 | else | |
419 | return alist; | |
420 | } | |
421 | ||
422 | ||
423 | SCM_PROC (s_assoc_remove_x, "assoc-remove!", 2, 0, 0, scm_assoc_remove_x); | |
424 | #ifdef __STDC__ | |
425 | SCM | |
426 | scm_assoc_remove_x (SCM alist, SCM key) | |
427 | #else | |
428 | SCM | |
429 | scm_assoc_remove_x (alist, key) | |
430 | SCM alist; | |
431 | SCM key; | |
432 | #endif | |
433 | { | |
434 | SCM handle; | |
435 | ||
436 | handle = scm_sloppy_assoc (key, alist); | |
437 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) | |
438 | { | |
439 | return scm_delete_x (handle, alist); | |
440 | } | |
441 | else | |
442 | return alist; | |
443 | } | |
444 | ||
445 | ||
446 | \f | |
447 | ||
448 | ||
449 | #ifdef __STDC__ | |
450 | void | |
451 | scm_init_alist (void) | |
452 | #else | |
453 | void | |
454 | scm_init_alist () | |
455 | #endif | |
456 | { | |
457 | #include "alist.x" | |
458 | } | |
459 |