/[guile]/guile/guile-core/libguile/environments.c
ViewVC logotype

Diff of /guile/guile-core/libguile/environments.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.29 by xxhanwen, Sun Jul 21 17:46:23 2002 UTC revision 1.30 by dirk, Wed Jul 24 16:34:43 2002 UTC
# Line 46  Line 46 
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"
# Line 587  obarray_retrieve (SCM obarray, SCM sym) Line 588  obarray_retrieve (SCM obarray, SCM sym)
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
# Line 640  obarray_remove (SCM obarray, SCM sym) Line 598  obarray_remove (SCM obarray, SCM sym)
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    

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26