diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | hash.c | 9 | ||||
-rw-r--r-- | hash.h | 1 |
4 files changed, 20 insertions, 0 deletions
@@ -1,5 +1,13 @@ 2011-11-29 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): hashp and maphash functions registered. + + * hash.c (maphash): New function. + + * hash.h (maphash): Declared. + +2011-11-29 Kaz Kylheku <kaz@kylheku.com> + * eval.c (expand_vars): Bugfix: was not handling vars of the form var, only (var initform). @@ -986,6 +986,8 @@ void eval_init(void) func_n1(get_hash_userdata)); reg_fun(intern(lit("set-hash-userdata"), user_package), func_n2(set_hash_userdata)); + reg_fun(intern(lit("hashp"), user_package), func_n1(hashp)); + reg_fun(intern(lit("maphash"), user_package), func_n2(maphash)); reg_fun(intern(lit("eval"), user_package), func_n2(eval_intrinsic)); @@ -395,6 +395,15 @@ val hash_next(val *iter) return car(hi->cons); } +val maphash(val fun, val hash) +{ + val iter = hash_begin(hash); + val cell; + while ((cell = hash_next(&iter)) != nil) + funcall2(fun, car(cell), cdr(cell)); + return nil; +} + /* * Called from garbage collector. Hash module must process all weak tables * that were visited during the marking phase, maintained in the list @@ -37,6 +37,7 @@ val hash_count(val hash); val get_hash_userdata(val hash); val set_hash_userdata(val hash, val data); val hashp(val obj); +val maphash(val func, val hash); val hash_begin(val hash); val hash_next(val *iter); |