summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-06-24 06:04:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-06-24 06:04:43 -0700
commit5a1a9076e10d03a070daa0e8c019fc0ec76e5c88 (patch)
treea57fb2920b46506fd80130a798e59389f8ea9ee5 /hash.c
parent2f654aa0a794581bb857c38e99e0abb185c53d52 (diff)
downloadtxr-5a1a9076e10d03a070daa0e8c019fc0ec76e5c88.tar.gz
txr-5a1a9076e10d03a070daa0e8c019fc0ec76e5c88.tar.bz2
txr-5a1a9076e10d03a070daa0e8c019fc0ec76e5c88.zip
* hash.c (hash_from_pairs, hash_list): New functions.
* hash.h (hash_from_pairs, hash_list): Declared. * eval.c (eval_init): Registered hash-from-pairs and hash-list intrinsic. * txr.1: Documented new functions.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 45e18298..4ece8a54 100644
--- a/hash.c
+++ b/hash.c
@@ -880,6 +880,25 @@ val hash_construct(val hashv_args, val pairs)
return hash;
}
+val hash_from_pairs(val pairs, val hashv_args)
+{
+ return hash_construct(default_bool_arg(hashv_args), pairs);
+}
+
+val hash_list(val keys, val hashv_args)
+{
+ val hash = hashv(default_bool_arg(hashv_args));
+
+ keys = nullify(keys);
+
+ for (; keys; keys = cdr(keys)) {
+ val key = car(keys);
+ sethash(hash, key, key);
+ }
+
+ return hash;
+}
+
val group_by(val func, val seq, val hashv_args)
{
val hash = hashv(hashv_args);