diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-09 23:01:53 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-09 23:01:53 -0700 |
commit | 07d3266440d15c67f450c6f0a26e85a1541f4395 (patch) | |
tree | 79939ce8df58e581528e41fb0eace3f827b62047 /lib.h | |
parent | 5cb27535f5f0cdbcc0eca8976cac47bd178ae230 (diff) | |
download | txr-07d3266440d15c67f450c6f0a26e85a1541f4395.tar.gz txr-07d3266440d15c67f450c6f0a26e85a1541f4395.tar.bz2 txr-07d3266440d15c67f450c6f0a26e85a1541f4395.zip |
lib: basic support for trees as sequences.
As of this commit, binary search trees can be iterated:
mapped over with mapcar and such.
* arith.c (poly, rpoly): rpoly won't work with trees. They
work just with vectors and lists so let's make the error
message more accurate. I noticed the self names of these two
are swapped; will fix in another commit.
* eval.c (tprint): Refactor to use iterator framework for
objects other than lists. The tree case falls into this,
so trees are supported.
* lib.h (enum seq_kind): New enum constant SEQ_TREELIKE.
(seq_iter_init_with_info): Declared.
* lib.c (seq_info): Map tree object to SEQ_TREELIKE type.
(seq_iter_get_tree, seq_iter_peek_tree): New static functions.
(seq_iter_rewind): Support rewinding tree iteration.
I think we could reuse the existing iterator here, and in the
hash case as well. I made a note to look into this.
(seq_iter_init_with_info): Internal linkage changed to
external, because tprint in eval.c uses this.
Handle SEQ_TREELIKE case here, by setting up iterator with the
two new static functions.
(seq_iter_mark): Handle SEQ_TREELIKE_CASE. Change switch
statement to exhaustively list cases.
(ldiff): Add SEQ_TREELIKE to various cases. Idea is that we
handle it like SEQ_HASH.
(nsort, sort, nshuffle, take, take_while, take_until,
drop_while, drop_until, update): Add case for SEQ_TREELIKE,
routing to error message.
(lazy_where_tree_func): New static function.
(where, sel, reject): Support trees.
Diffstat (limited to 'lib.h')
-rw-r--r-- | lib.h | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -378,7 +378,7 @@ typedef val *loc; #endif typedef enum seq_kind { - SEQ_NIL, SEQ_LISTLIKE, SEQ_VECLIKE, SEQ_HASHLIKE, SEQ_NOTSEQ + SEQ_NIL, SEQ_LISTLIKE, SEQ_VECLIKE, SEQ_HASHLIKE, SEQ_TREELIKE, SEQ_NOTSEQ } seq_kind_t; typedef struct seq_info { @@ -554,6 +554,8 @@ val typeof(val obj); val subtypep(val sub, val sup); val typep(val obj, val type); seq_info_t seq_info(val cobj); +void seq_iter_init_with_info(val self, seq_iter_t *it, + seq_info_t si, int support_rewind); void seq_iter_init(val self, seq_iter_t *it, val obj); INLINE int seq_get(seq_iter_t *it, val *pval) { return it->get(it, pval); } INLINE int seq_peek(seq_iter_t *it, val *pval) { return it->peek(it, pval); } |