summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--eval.c2
-rw-r--r--hash.c9
-rw-r--r--hash.h1
4 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 88b31abe..2f6c09e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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).
diff --git a/eval.c b/eval.c
index 5ae61d71..b59bbcc6 100644
--- a/eval.c
+++ b/eval.c
@@ -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));
diff --git a/hash.c b/hash.c
index 010cfbf6..618acc75 100644
--- a/hash.c
+++ b/hash.c
@@ -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
diff --git a/hash.h b/hash.h
index 7526b746..367ccfff 100644
--- a/hash.h
+++ b/hash.h
@@ -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);