diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-04-07 09:25:07 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-04-07 09:25:07 -0700 |
commit | ec19948f35d876f5c64814a2905760b2f8763bb4 (patch) | |
tree | 14c5a24be8cec4f2fee10cda36d3f9379dd17851 /eval.c | |
parent | 10d60eea8cf8c3b60d9df1d2fc7621833a2ee79c (diff) | |
download | txr-ec19948f35d876f5c64814a2905760b2f8763bb4.tar.gz txr-ec19948f35d876f5c64814a2905760b2f8763bb4.tar.bz2 txr-ec19948f35d876f5c64814a2905760b2f8763bb4.zip |
Rounding out hash table functionality with lazy lists that
can walk table content in different ways.
* eval.c (op_dohash): Follow interface change of hash_next.
(eval_init): hash-keys, hash-values, hash-pairs and hash-alist
intrinsics introduced.
* filter.c (trie_compress): Follow interface change of hash_next.
* hash.c (hash_next): Silly interface which takes a pointer to
the iterator has changed to just take the iterator. The function
unambiguously returns nil when the iteration ends, so there
is no need to set the iterator variable to nil.
(maphash): Follows interface change of hash_next.
(hash_keys_lazy, hash_values_lazy, hash_pairs_lazy, hash_alist_lazy):
New static functions.
(hash_keys, hash_values, hash_pairs, hash_alist): New functions.
* hash.h (hash_next): Declaration updated.
(hash_keys, hash_values, hash_pairs, hash_alist): Declared.
* lib.c (make_half_lazy_cons): New way of constructing lazy cons,
with the car field specified. It simplifies situations when the
previous cons computes the car of the next one. Why hadn't I thought of
this before?
* lib.h (make_half_lazy_cons): Declared.
* txr.1: Doc stubs for new hash functions.
* txr.vim: Highlighting for new hash functions.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -1035,7 +1035,7 @@ static val op_dohash(val form, val env) uw_block_begin (nil, result); - while ((cell = hash_next(&iter)) != nil) { + while ((cell = hash_next(iter)) != nil) { /* These assignments are gc-safe, because keyvar and valvar are newer objects than existing entries in the hash, unless the body mutates hash by inserting newer objects, @@ -2241,6 +2241,10 @@ void eval_init(void) reg_fun(intern(lit("maphash"), user_package), func_n2(maphash)); reg_fun(intern(lit("hash-eql"), user_package), func_n1(hash_eql)); reg_fun(intern(lit("hash-equal"), user_package), func_n1(hash_equal)); + reg_fun(intern(lit("hash-keys"), user_package), func_n1(hash_keys)); + reg_fun(intern(lit("hash-values"), user_package), func_n1(hash_values)); + reg_fun(intern(lit("hash-pairs"), user_package), func_n1(hash_pairs)); + reg_fun(intern(lit("hash-alist"), user_package), func_n1(hash_alist)); reg_fun(intern(lit("eval"), user_package), func_n2o(eval_intrinsic, 1)); |