#include #include #include "../runtime/gyehoek.h" #include "../runtime/weak-set.h" static int symbol_lookup_predicate_fn (SCM sym1, void *closure) { const SCM sym2 = *((SCM*)closure); const int symp1 = SCM_SYMBOLP (sym1); const int symp2 = SCM_SYMBOLP (sym2); // both symbols? if (SCM_SYMBOLP (sym1) && SCM_SYMBOLP (sym2)) { const SCM str1 = SCM_CELL_OBJECT (sym1, 2); const SCM str2 = SCM_CELL_OBJECT (sym2, 2); const size_t len1 = scm_c_string_length (str1); const size_t len2 = scm_c_string_length (str2); // same length? if (len1 == len2) { // same name? const char * const s1 = scm_c_string_chars (str1); const char * const s2 = scm_c_string_chars (str2); return strncmp (s1, s2, len1); } } return 0; } SCM test (SCM set, const char *sym_name, SCM value) { SCM str = scm_from_cstring (sym_name); SCM sym = scm_make_symbol (str, scm_c_hash (str)); SCM r = scm_c_weak_set_insert (set, scm_c_hash (str), value, symbol_lookup_predicate_fn, &sym); printf ("%ld\n", weak_set_count (set)); return r; } int main () { /* const char s[] = "wormy"; */ /* const SCM str = scm_from_utf8_string (s, sizeof(s)); */ /* const unsigned long hash = scm_c_hash (str); */ /* printf ("%ld\n", hash); */ SCM set = scm_c_make_weak_set (31); test (set, "my-symbol", SCM_PACK (SCM_MAKE_SMALL_INT (123))); test (set, "my-symbol", SCM_PACK (SCM_MAKE_SMALL_INT (123))); test (set, "my-symbol2", SCM_PACK (SCM_MAKE_SMALL_INT (456))); }