summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-06-02 06:13:00 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-06-02 06:13:00 -0700
commitdcd0c4e0485ad5f8cf571bffa99add57c8aed183 (patch)
treecd17a850e3434b749a7366adf9668cd5e1a11fe9 /eval.c
parent7d6e2b419916c915543e36f14891773294687b99 (diff)
downloadtxr-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.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index e94b4c14..7f3e2b23 100644
--- a/eval.c
+++ b/eval.c
@@ -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));