diff options
author | Rob Browning <rlb@defaultvalue.org> | 2020-02-16 12:12:08 -0600 |
---|---|---|
committer | Rob Browning <rlb@defaultvalue.org> | 2020-02-21 01:36:14 -0600 |
commit | 8b3cad618314f02ad3921fa104f17ca0f721dfcb (patch) | |
tree | f4c4180858f0650b267badb8d81c69f2cf6418da | |
parent | cc30168878972652ddde4489351b76dc53f20142 (diff) | |
download | guile-8b3cad618314f02ad3921fa104f17ca0f721dfcb.tar.gz |
Implement hashing for keywords, i.e. (hash #:x ...)
Add keyword handling to (hash ...). Previously it would just return the
same value for all keywords.
* libguile/hash.c (scm_raw_ihash): Add scm_tc7_keyword case.
* libguile/keywords.h (SCM_I_KEYWORD_HASH): New macro.
-rw-r--r-- | libguile/hash.c | 3 | ||||
-rw-r--r-- | libguile/keywords.h | 2 |
2 files changed, 5 insertions, 0 deletions
diff --git a/libguile/hash.c b/libguile/hash.c index d6e93dae0..c51a794c9 100644 --- a/libguile/hash.c +++ b/libguile/hash.c @@ -35,6 +35,7 @@ #include "chars.h" #include "foreign.h" #include "gsubr.h" +#include "keywords.h" #include "numbers.h" #include "pairs.h" #include "ports.h" @@ -307,6 +308,8 @@ scm_raw_ihash (SCM obj, size_t depth) return scm_i_string_hash (obj); case scm_tc7_symbol: return scm_i_symbol_hash (obj); + case scm_tc7_keyword: + return SCM_I_KEYWORD_HASH (obj); case scm_tc7_pointer: return scm_raw_ihashq ((uintptr_t) SCM_POINTER_VALUE (obj)); case scm_tc7_wvect: diff --git a/libguile/keywords.h b/libguile/keywords.h index c8f480869..cb8598d8b 100644 --- a/libguile/keywords.h +++ b/libguile/keywords.h @@ -60,6 +60,8 @@ SCM_API void scm_c_bind_keyword_arguments (const char *subr, SCM rest, scm_t_keyword_arguments_flags flags, ...); +#define SCM_I_KEYWORD_HASH(x) scm_i_symbol_hash (SCM_CELL_OBJECT_1 (x)) + SCM_INTERNAL void scm_init_keywords (void); #endif /* SCM_KEYWORDS_H */ |