46 |
#include "libguile/eval.h" |
#include "libguile/eval.h" |
47 |
#include "libguile/gh.h" |
#include "libguile/gh.h" |
48 |
#include "libguile/hash.h" |
#include "libguile/hash.h" |
49 |
|
#include "libguile/list.h" |
50 |
#include "libguile/ports.h" |
#include "libguile/ports.h" |
51 |
#include "libguile/smob.h" |
#include "libguile/smob.h" |
52 |
#include "libguile/symbols.h" |
#include "libguile/symbols.h" |
588 |
return SCM_UNDEFINED; |
return SCM_UNDEFINED; |
589 |
} |
} |
590 |
|
|
|
/* |
|
|
Remove first occurance of KEY from (cdr ALIST), |
|
|
return (KEY . VAL) if found, otherwise return #f |
|
|
|
|
|
PRECONDITION: |
|
|
|
|
|
length (ALIST) >= 1 |
|
|
|
|
|
This could also be done by combining scm_delq1_x () and |
|
|
scm_sloppy_assq(), at the cost of walking the list another time. |
|
|
*/ |
|
|
static |
|
|
SCM |
|
|
remove_key_from_alist (SCM alist, SCM key) |
|
|
{ |
|
|
SCM cell_cdr = alist; |
|
|
alist =SCM_CDR (alist); |
|
|
|
|
|
/* |
|
|
inv: cdr(cell_cdr) == alist |
|
|
*/ |
|
|
while (!SCM_NULLP (alist)) |
|
|
{ |
|
|
if (SCM_EQ_P(SCM_CAAR (alist), key)) |
|
|
{ |
|
|
SCM entry = SCM_CAR(alist); |
|
|
SCM_SETCDR(cell_cdr, SCM_CDR (alist)); |
|
|
|
|
|
return entry; |
|
|
} |
|
|
else |
|
|
{ |
|
|
cell_cdr = SCM_CDR (cell_cdr); |
|
|
} |
|
|
|
|
|
if (!SCM_NULLP(alist)) |
|
|
alist = SCM_CDR (alist); |
|
|
} |
|
|
|
|
|
return SCM_BOOL_F; |
|
|
} |
|
|
|
|
|
|
|
591 |
|
|
592 |
/* |
/* |
593 |
* Remove entry from obarray. If the symbol was found and removed, the old |
* Remove entry from obarray. If the symbol was found and removed, the old |
598 |
{ |
{ |
599 |
size_t hash = SCM_SYMBOL_HASH (sym) % SCM_VECTOR_LENGTH (obarray); |
size_t hash = SCM_SYMBOL_HASH (sym) % SCM_VECTOR_LENGTH (obarray); |
600 |
SCM table_entry = SCM_VELTS (obarray)[hash]; |
SCM table_entry = SCM_VELTS (obarray)[hash]; |
601 |
|
SCM handle = scm_sloppy_assq (sym, table_entry); |
602 |
|
|
603 |
if (SCM_NULLP(table_entry)) |
if (SCM_CONSP (handle)) |
|
return SCM_BOOL_F; |
|
|
|
|
|
if (SCM_EQ_P (SCM_CAAR (table_entry), sym)) |
|
|
{ |
|
|
SCM_VECTOR_SET (obarray, hash, SCM_CDR(table_entry)); |
|
|
return SCM_CAR(table_entry); |
|
|
} |
|
|
else |
|
604 |
{ |
{ |
605 |
return remove_key_from_alist (table_entry, sym); |
SCM new_table_entry = scm_delq1_x (handle, table_entry); |
606 |
|
SCM_VECTOR_SET (obarray, hash, new_table_entry); |
607 |
} |
} |
608 |
|
|
609 |
|
return handle; |
610 |
} |
} |
611 |
|
|
612 |
|
|