| 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" |
| 44 | |
| 45 | \f |
| 46 | |
| 47 | SCM_PROC(s_acons, "acons", 3, 0, 0, scm_acons); |
| 48 | #ifdef __STDC__ |
| 49 | SCM |
| 50 | scm_acons (SCM w, SCM x, SCM y) |
| 51 | #else |
| 52 | SCM |
| 53 | scm_acons (w, x, y) |
| 54 | SCM w; |
| 55 | SCM x; |
| 56 | SCM y; |
| 57 | #endif |
| 58 | { |
| 59 | register SCM z; |
| 60 | SCM_NEWCELL (z); |
| 61 | SCM_CAR (z) = w; |
| 62 | SCM_CDR (z) = x; |
| 63 | x = z; |
| 64 | SCM_NEWCELL (z); |
| 65 | SCM_CAR (z) = x; |
| 66 | SCM_CDR (z) = y; |
| 67 | return z; |
| 68 | } |
| 69 | |
| 70 | \f |
| 71 | |
| 72 | SCM_PROC (s_sloppy_assq, "sloppy-assq", 2, 0, 0, scm_sloppy_assq); |
| 73 | #ifdef __STDC__ |
| 74 | SCM |
| 75 | scm_sloppy_assq(SCM x, SCM alist) |
| 76 | #else |
| 77 | SCM |
| 78 | scm_sloppy_assq(x, alist) |
| 79 | SCM x; |
| 80 | SCM alist; |
| 81 | #endif |
| 82 | { |
| 83 | SCM tmp; |
| 84 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) |
| 85 | { |
| 86 | if (SCM_CONSP(alist)) |
| 87 | { |
| 88 | tmp = SCM_CAR(alist); |
| 89 | if (SCM_NIMP (tmp) && SCM_CONSP (tmp) && (SCM_CAR (tmp)==x)) |
| 90 | return tmp; |
| 91 | } |
| 92 | } |
| 93 | return SCM_BOOL_F; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | |
| 98 | SCM_PROC (s_sloppy_assv, "sloppy-assv", 2, 0, 0, scm_sloppy_assv); |
| 99 | #ifdef __STDC__ |
| 100 | SCM |
| 101 | scm_sloppy_assv(SCM x, SCM alist) |
| 102 | #else |
| 103 | SCM |
| 104 | scm_sloppy_assv(x, alist) |
| 105 | SCM x; |
| 106 | SCM alist; |
| 107 | #endif |
| 108 | { |
| 109 | SCM tmp; |
| 110 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) |
| 111 | { |
| 112 | if (SCM_CONSP(alist)) |
| 113 | { |
| 114 | tmp = SCM_CAR(alist); |
| 115 | if ( SCM_NIMP (tmp) |
| 116 | && SCM_CONSP (tmp) |
| 117 | && SCM_NFALSEP (scm_eqv_p (SCM_CAR (tmp), x))) |
| 118 | return tmp; |
| 119 | } |
| 120 | } |
| 121 | return SCM_BOOL_F; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | SCM_PROC (s_sloppy_assoc, "sloppy-assoc", 2, 0, 0, scm_sloppy_assoc); |
| 126 | #ifdef __STDC__ |
| 127 | SCM |
| 128 | scm_sloppy_assoc(SCM x, SCM alist) |
| 129 | #else |
| 130 | SCM |
| 131 | scm_sloppy_assoc(x, alist) |
| 132 | SCM x; |
| 133 | SCM alist; |
| 134 | #endif |
| 135 | { |
| 136 | SCM tmp; |
| 137 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) |
| 138 | { |
| 139 | if (SCM_CONSP(alist)) |
| 140 | { |
| 141 | tmp = SCM_CAR(alist); |
| 142 | if ( SCM_NIMP (tmp) |
| 143 | && SCM_CONSP (tmp) |
| 144 | && SCM_NFALSEP (scm_equal_p (SCM_CAR (tmp), x))) |
| 145 | return tmp; |
| 146 | } |
| 147 | } |
| 148 | return SCM_BOOL_F; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | \f |
| 153 | |
| 154 | SCM_PROC(s_assq, "assq", 2, 0, 0, scm_assq); |
| 155 | #ifdef __STDC__ |
| 156 | SCM |
| 157 | scm_assq(SCM x, SCM alist) |
| 158 | #else |
| 159 | SCM |
| 160 | scm_assq(x, alist) |
| 161 | SCM x; |
| 162 | SCM alist; |
| 163 | #endif |
| 164 | { |
| 165 | SCM tmp; |
| 166 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) { |
| 167 | SCM_ASSERT(SCM_CONSP(alist), alist, SCM_ARG2, s_assq); |
| 168 | tmp = SCM_CAR(alist); |
| 169 | SCM_ASSERT(SCM_NIMP(tmp) && SCM_CONSP(tmp), alist, SCM_ARG2, s_assq); |
| 170 | if (SCM_CAR(tmp)==x) return tmp; |
| 171 | } |
| 172 | SCM_ASSERT(SCM_NULLP(alist), alist, SCM_ARG2, s_assq); |
| 173 | return SCM_BOOL_F; |
| 174 | } |
| 175 | |
| 176 | |
| 177 | SCM_PROC(s_assv, "assv", 2, 0, 0, scm_assv); |
| 178 | #ifdef __STDC__ |
| 179 | SCM |
| 180 | scm_assv(SCM x, SCM alist) |
| 181 | #else |
| 182 | SCM |
| 183 | scm_assv(x, alist) |
| 184 | SCM x; |
| 185 | SCM alist; |
| 186 | #endif |
| 187 | { |
| 188 | SCM tmp; |
| 189 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) { |
| 190 | SCM_ASRTGO(SCM_CONSP(alist), badlst); |
| 191 | tmp = SCM_CAR(alist); |
| 192 | SCM_ASRTGO(SCM_NIMP(tmp) && SCM_CONSP(tmp), badlst); |
| 193 | if SCM_NFALSEP(scm_eqv_p(SCM_CAR(tmp), x)) return tmp; |
| 194 | } |
| 195 | # ifndef RECKLESS |
| 196 | if (!(SCM_NULLP(alist))) |
| 197 | badlst: scm_wta(alist, (char *)SCM_ARG2, s_assv); |
| 198 | # endif |
| 199 | return SCM_BOOL_F; |
| 200 | } |
| 201 | |
| 202 | |
| 203 | SCM_PROC(s_assoc, "assoc", 2, 0, 0, scm_assoc); |
| 204 | #ifdef __STDC__ |
| 205 | SCM |
| 206 | scm_assoc(SCM x, SCM alist) |
| 207 | #else |
| 208 | SCM |
| 209 | scm_assoc(x, alist) |
| 210 | SCM x; |
| 211 | SCM alist; |
| 212 | #endif |
| 213 | { |
| 214 | SCM tmp; |
| 215 | for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) { |
| 216 | SCM_ASSERT(SCM_CONSP(alist), alist, SCM_ARG2, s_assoc); |
| 217 | tmp = SCM_CAR(alist); |
| 218 | SCM_ASSERT(SCM_NIMP(tmp) && SCM_CONSP(tmp), alist, SCM_ARG2, s_assoc); |
| 219 | if SCM_NFALSEP(scm_equal_p(SCM_CAR(tmp), x)) return tmp; |
| 220 | } |
| 221 | SCM_ASSERT(SCM_NULLP(alist), alist, SCM_ARG2, s_assoc); |
| 222 | return SCM_BOOL_F; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | \f |
| 227 | |
| 228 | SCM_PROC (s_assq_ref, "assq-ref", 2, 0, 0, scm_assq_ref); |
| 229 | #ifdef __STDC__ |
| 230 | SCM |
| 231 | scm_assq_ref (SCM alist, SCM key) |
| 232 | #else |
| 233 | SCM |
| 234 | scm_assq_ref (alist, key) |
| 235 | SCM alist; |
| 236 | SCM key; |
| 237 | #endif |
| 238 | { |
| 239 | SCM handle; |
| 240 | |
| 241 | handle = scm_sloppy_assq (key, alist); |
| 242 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 243 | { |
| 244 | return SCM_CDR (handle); |
| 245 | } |
| 246 | return SCM_BOOL_F; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | SCM_PROC (s_assv_ref, "assv-ref", 2, 0, 0, scm_assv_ref); |
| 251 | #ifdef __STDC__ |
| 252 | SCM |
| 253 | scm_assv_ref (SCM alist, SCM key) |
| 254 | #else |
| 255 | SCM |
| 256 | scm_assv_ref (alist, key) |
| 257 | SCM alist; |
| 258 | SCM key; |
| 259 | #endif |
| 260 | { |
| 261 | SCM handle; |
| 262 | |
| 263 | handle = scm_sloppy_assv (key, alist); |
| 264 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 265 | { |
| 266 | return SCM_CDR (handle); |
| 267 | } |
| 268 | return SCM_BOOL_F; |
| 269 | } |
| 270 | |
| 271 | |
| 272 | SCM_PROC (s_assoc_ref, "assoc-ref", 2, 0, 0, scm_assoc_ref); |
| 273 | #ifdef __STDC__ |
| 274 | SCM |
| 275 | scm_assoc_ref (SCM alist, SCM key) |
| 276 | #else |
| 277 | SCM |
| 278 | scm_assoc_ref (alist, key) |
| 279 | SCM alist; |
| 280 | SCM key; |
| 281 | #endif |
| 282 | { |
| 283 | SCM handle; |
| 284 | |
| 285 | handle = scm_sloppy_assoc (key, alist); |
| 286 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 287 | { |
| 288 | return SCM_CDR (handle); |
| 289 | } |
| 290 | return SCM_BOOL_F; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | |
| 295 | \f |
| 296 | |
| 297 | |
| 298 | SCM_PROC (s_assq_set_x, "assq-set!", 3, 0, 0, scm_assq_set_x); |
| 299 | #ifdef __STDC__ |
| 300 | SCM |
| 301 | scm_assq_set_x (SCM alist, SCM key, SCM val) |
| 302 | #else |
| 303 | SCM |
| 304 | scm_assq_set_x (alist, key, val) |
| 305 | SCM alist; |
| 306 | SCM key; |
| 307 | SCM val; |
| 308 | #endif |
| 309 | { |
| 310 | SCM handle; |
| 311 | |
| 312 | handle = scm_sloppy_assq (key, alist); |
| 313 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 314 | { |
| 315 | SCM_SETCDR (handle, val); |
| 316 | return alist; |
| 317 | } |
| 318 | else |
| 319 | return scm_acons (key, val, alist); |
| 320 | } |
| 321 | |
| 322 | SCM_PROC (s_assv_set_x, "assv-set!", 3, 0, 0, scm_assv_set_x); |
| 323 | #ifdef __STDC__ |
| 324 | SCM |
| 325 | scm_assv_set_x (SCM alist, SCM key, SCM val) |
| 326 | #else |
| 327 | SCM |
| 328 | scm_assv_set_x (alist, key, val) |
| 329 | SCM alist; |
| 330 | SCM key; |
| 331 | SCM val; |
| 332 | #endif |
| 333 | { |
| 334 | SCM handle; |
| 335 | |
| 336 | handle = scm_sloppy_assv (key, alist); |
| 337 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 338 | { |
| 339 | SCM_SETCDR (handle, val); |
| 340 | return alist; |
| 341 | } |
| 342 | else |
| 343 | return scm_acons (key, val, alist); |
| 344 | } |
| 345 | |
| 346 | SCM_PROC (s_assoc_set_x, "assoc-set!", 3, 0, 0, scm_assoc_set_x); |
| 347 | #ifdef __STDC__ |
| 348 | SCM |
| 349 | scm_assoc_set_x (SCM alist, SCM key, SCM val) |
| 350 | #else |
| 351 | SCM |
| 352 | scm_assoc_set_x (alist, key, val) |
| 353 | SCM alist; |
| 354 | SCM key; |
| 355 | SCM val; |
| 356 | #endif |
| 357 | { |
| 358 | SCM handle; |
| 359 | |
| 360 | handle = scm_sloppy_assoc (key, alist); |
| 361 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 362 | { |
| 363 | SCM_SETCDR (handle, val); |
| 364 | return alist; |
| 365 | } |
| 366 | else |
| 367 | return scm_acons (key, val, alist); |
| 368 | } |
| 369 | |
| 370 | |
| 371 | \f |
| 372 | |
| 373 | SCM_PROC (s_assq_remove_x, "assq-remove!", 2, 0, 0, scm_assq_remove_x); |
| 374 | #ifdef __STDC__ |
| 375 | SCM |
| 376 | scm_assq_remove_x (SCM alist, SCM key) |
| 377 | #else |
| 378 | SCM |
| 379 | scm_assq_remove_x (alist, key) |
| 380 | SCM alist; |
| 381 | SCM key; |
| 382 | #endif |
| 383 | { |
| 384 | SCM handle; |
| 385 | |
| 386 | handle = scm_sloppy_assq (key, alist); |
| 387 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 388 | { |
| 389 | return scm_delq_x (handle, alist); |
| 390 | } |
| 391 | else |
| 392 | return alist; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | SCM_PROC (s_assv_remove_x, "assv-remove!", 2, 0, 0, scm_assv_remove_x); |
| 397 | #ifdef __STDC__ |
| 398 | SCM |
| 399 | scm_assv_remove_x (SCM alist, SCM key) |
| 400 | #else |
| 401 | SCM |
| 402 | scm_assv_remove_x (alist, key) |
| 403 | SCM alist; |
| 404 | SCM key; |
| 405 | #endif |
| 406 | { |
| 407 | SCM handle; |
| 408 | |
| 409 | handle = scm_sloppy_assv (key, alist); |
| 410 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 411 | { |
| 412 | return scm_delv_x (handle, alist); |
| 413 | } |
| 414 | else |
| 415 | return alist; |
| 416 | } |
| 417 | |
| 418 | |
| 419 | SCM_PROC (s_assoc_remove_x, "assoc-remove!", 2, 0, 0, scm_assoc_remove_x); |
| 420 | #ifdef __STDC__ |
| 421 | SCM |
| 422 | scm_assoc_remove_x (SCM alist, SCM key) |
| 423 | #else |
| 424 | SCM |
| 425 | scm_assoc_remove_x (alist, key) |
| 426 | SCM alist; |
| 427 | SCM key; |
| 428 | #endif |
| 429 | { |
| 430 | SCM handle; |
| 431 | |
| 432 | handle = scm_sloppy_assoc (key, alist); |
| 433 | if (SCM_NIMP (handle) && SCM_CONSP (handle)) |
| 434 | { |
| 435 | return scm_delete_x (handle, alist); |
| 436 | } |
| 437 | else |
| 438 | return alist; |
| 439 | } |
| 440 | |
| 441 | |
| 442 | \f |
| 443 | |
| 444 | |
| 445 | #ifdef __STDC__ |
| 446 | void |
| 447 | scm_init_alist (void) |
| 448 | #else |
| 449 | void |
| 450 | scm_init_alist () |
| 451 | #endif |
| 452 | { |
| 453 | #include "alist.x" |
| 454 | } |
| 455 | |