diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-06-24 06:04:43 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-06-24 06:04:43 -0700 |
commit | 5a1a9076e10d03a070daa0e8c019fc0ec76e5c88 (patch) | |
tree | a57fb2920b46506fd80130a798e59389f8ea9ee5 /hash.c | |
parent | 2f654aa0a794581bb857c38e99e0abb185c53d52 (diff) | |
download | txr-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.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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); |