1 /* Copyright (C) 1995,1996 Free Software Foundation, Inc.
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)
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.
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.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
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.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
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.
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.
51 SCM_PROC(s_acons
, "acons", 3, 0, 0, scm_acons
);
72 SCM_PROC (s_sloppy_assq
, "sloppy-assq", 2, 0, 0, scm_sloppy_assq
);
75 scm_sloppy_assq(x
, alist
)
80 for (; SCM_NIMP (alist
) && SCM_CONSP (alist
); alist
= SCM_CDR (alist
))
82 SCM tmp
= SCM_CAR(alist
);
83 if (SCM_NIMP (tmp
) && SCM_CONSP (tmp
) && (SCM_CAR (tmp
)==x
))
91 SCM_PROC (s_sloppy_assv
, "sloppy-assv", 2, 0, 0, scm_sloppy_assv
);
94 scm_sloppy_assv(x
, alist
)
98 for (; SCM_NIMP (alist
) && SCM_CONSP (alist
); alist
= SCM_CDR (alist
))
100 SCM tmp
= SCM_CAR(alist
);
103 && SCM_NFALSEP (scm_eqv_p (SCM_CAR (tmp
), x
)))
110 SCM_PROC (s_sloppy_assoc
, "sloppy-assoc", 2, 0, 0, scm_sloppy_assoc
);
113 scm_sloppy_assoc(x
, alist
)
117 for (; SCM_NIMP (alist
) && SCM_CONSP (alist
); alist
= SCM_CDR (alist
))
119 SCM tmp
= SCM_CAR(alist
);
122 && SCM_NFALSEP (scm_equal_p (SCM_CAR (tmp
), x
)))
131 SCM_PROC(s_assq
, "assq", 2, 0, 0, scm_assq
);
139 for(;SCM_NIMP(alist
);alist
= SCM_CDR(alist
)) {
140 SCM_ASSERT(SCM_CONSP(alist
), alist
, SCM_ARG2
, s_assq
);
141 tmp
= SCM_CAR(alist
);
142 SCM_ASSERT(SCM_NIMP(tmp
) && SCM_CONSP(tmp
), alist
, SCM_ARG2
, s_assq
);
143 if (SCM_CAR(tmp
)==x
) return tmp
;
145 SCM_ASSERT(SCM_NULLP(alist
), alist
, SCM_ARG2
, s_assq
);
150 SCM_PROC(s_assv
, "assv", 2, 0, 0, scm_assv
);
158 for(;SCM_NIMP(alist
);alist
= SCM_CDR(alist
)) {
159 SCM_ASRTGO(SCM_CONSP(alist
), badlst
);
160 tmp
= SCM_CAR(alist
);
161 SCM_ASRTGO(SCM_NIMP(tmp
) && SCM_CONSP(tmp
), badlst
);
162 if SCM_NFALSEP(scm_eqv_p(SCM_CAR(tmp
), x
)) return tmp
;
165 if (!(SCM_NULLP(alist
)))
166 badlst
: scm_wta(alist
, (char *)SCM_ARG2
, s_assv
);
172 SCM_PROC(s_assoc
, "assoc", 2, 0, 0, scm_assoc
);
180 for(;SCM_NIMP(alist
);alist
= SCM_CDR(alist
)) {
181 SCM_ASSERT(SCM_CONSP(alist
), alist
, SCM_ARG2
, s_assoc
);
182 tmp
= SCM_CAR(alist
);
183 SCM_ASSERT(SCM_NIMP(tmp
) && SCM_CONSP(tmp
), alist
, SCM_ARG2
, s_assoc
);
184 if SCM_NFALSEP(scm_equal_p(SCM_CAR(tmp
), x
)) return tmp
;
186 SCM_ASSERT(SCM_NULLP(alist
), alist
, SCM_ARG2
, s_assoc
);
193 SCM_PROC (s_assq_ref
, "assq-ref", 2, 0, 0, scm_assq_ref
);
196 scm_assq_ref (alist
, key
)
202 handle
= scm_sloppy_assq (key
, alist
);
203 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
205 return SCM_CDR (handle
);
211 SCM_PROC (s_assv_ref
, "assv-ref", 2, 0, 0, scm_assv_ref
);
214 scm_assv_ref (alist
, key
)
220 handle
= scm_sloppy_assv (key
, alist
);
221 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
223 return SCM_CDR (handle
);
229 SCM_PROC (s_assoc_ref
, "assoc-ref", 2, 0, 0, scm_assoc_ref
);
232 scm_assoc_ref (alist
, key
)
238 handle
= scm_sloppy_assoc (key
, alist
);
239 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
241 return SCM_CDR (handle
);
251 SCM_PROC (s_assq_set_x
, "assq-set!", 3, 0, 0, scm_assq_set_x
);
254 scm_assq_set_x (alist
, key
, val
)
261 handle
= scm_sloppy_assq (key
, alist
);
262 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
264 SCM_SETCDR (handle
, val
);
268 return scm_acons (key
, val
, alist
);
271 SCM_PROC (s_assv_set_x
, "assv-set!", 3, 0, 0, scm_assv_set_x
);
274 scm_assv_set_x (alist
, key
, val
)
281 handle
= scm_sloppy_assv (key
, alist
);
282 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
284 SCM_SETCDR (handle
, val
);
288 return scm_acons (key
, val
, alist
);
291 SCM_PROC (s_assoc_set_x
, "assoc-set!", 3, 0, 0, scm_assoc_set_x
);
294 scm_assoc_set_x (alist
, key
, val
)
301 handle
= scm_sloppy_assoc (key
, alist
);
302 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
304 SCM_SETCDR (handle
, val
);
308 return scm_acons (key
, val
, alist
);
314 SCM_PROC (s_assq_remove_x
, "assq-remove!", 2, 0, 0, scm_assq_remove_x
);
317 scm_assq_remove_x (alist
, key
)
323 handle
= scm_sloppy_assq (key
, alist
);
324 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
326 return scm_delq_x (handle
, alist
);
333 SCM_PROC (s_assv_remove_x
, "assv-remove!", 2, 0, 0, scm_assv_remove_x
);
336 scm_assv_remove_x (alist
, key
)
342 handle
= scm_sloppy_assv (key
, alist
);
343 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
345 return scm_delv_x (handle
, alist
);
352 SCM_PROC (s_assoc_remove_x
, "assoc-remove!", 2, 0, 0, scm_assoc_remove_x
);
355 scm_assoc_remove_x (alist
, key
)
361 handle
= scm_sloppy_assoc (key
, alist
);
362 if (SCM_NIMP (handle
) && SCM_CONSP (handle
))
364 return scm_delete_x (handle
, alist
);