diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-06-02 06:13:00 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-06-02 06:13:00 -0700 |
commit | dcd0c4e0485ad5f8cf571bffa99add57c8aed183 (patch) | |
tree | cd17a850e3434b749a7366adf9668cd5e1a11fe9 /eval.c | |
parent | 7d6e2b419916c915543e36f14891773294687b99 (diff) | |
download | txr-dcd0c4e0485ad5f8cf571bffa99add57c8aed183.tar.gz txr-dcd0c4e0485ad5f8cf571bffa99add57c8aed183.tar.bz2 txr-dcd0c4e0485ad5f8cf571bffa99add57c8aed183.zip |
New style iteration functions.
iter-begin provides a paradigm for iteration that is more
compatible with lists. If the sequence is a list, then the
list itself is returned as the iterator, and the other
functions are basicaly wrappers for car/cdr and null testing.
Yet the API is defined in such a way that other objects can be
iterated with good efficiency, at the cost of allocating a new
iterator object (which can be re-used).
* eval.c (eval_init): Register iter-begin, iter-more,
iter-item, iter-step and iter-reset.
* lib.c (seq_iter_init_with_info): New static function.
(seq_iter_init): Now a thin wrapper for
seq_iter_init_with_info.
(iter_begin, iter_more, iter_item, iter_step, iter_reset): New
functions.
* lib.h (iter_begin, iter_more, iter_item, iter_step,
iter_reset): New functions.
* txr.1: Documented.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -6970,6 +6970,11 @@ void eval_init(void) reg_fun(intern(lit("seq-begin"), user_package), func_n1(seq_begin)); reg_fun(intern(lit("seq-next"), user_package), func_n2(seq_next)); reg_fun(intern(lit("seq-reset"), user_package), func_n2(seq_reset)); + reg_fun(intern(lit("iter-begin"), user_package), func_n1(iter_begin)); + reg_fun(intern(lit("iter-more"), user_package), func_n1(iter_more)); + reg_fun(intern(lit("iter-item"), user_package), func_n1(iter_item)); + reg_fun(intern(lit("iter-step"), user_package), func_n1(iter_step)); + reg_fun(intern(lit("iter-reset"), user_package), func_n2(iter_reset)); reg_fun(intern(lit("rcons"), user_package), func_n2(rcons)); reg_fun(intern(lit("rangep"), user_package), func_n1(rangep)); |