summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-03-07 00:11:37 -0800
committerKaz Kylheku <kaz@kylheku.com>2025-03-07 00:11:37 -0800
commit07e40c025d65beeced5ac83485eb13dab9b7d2ae (patch)
tree8a6569af89018d5d9ff2622c8f7ad40fd236fd0e /lib.c
parenta68a67376127cb9accf26c4ed43438f188eb24c8 (diff)
downloadtxr-07e40c025d65beeced5ac83485eb13dab9b7d2ae.tar.gz
txr-07e40c025d65beeced5ac83485eb13dab9b7d2ae.tar.bz2
txr-07e40c025d65beeced5ac83485eb13dab9b7d2ae.zip
New function: iterp.
* eval.c (eval_init): Register iterp intrinsic. * lib.[ch] (iterp): New function. * tests/012/iter.tl: New tests. * txr.1: Document iterp. Update documentation for iter-more, iter-item and iter-step to more precisely identify which objects are valid arguments in terms of iterp and additional conditions, and that other objects throw a type-error exception. Fix wrong references to iter-more under documentation for iter-item. Removed obsolete text specifying that iter-step uses car on list-like sequences, a dubious behavior removed in the previous commit.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 1e127e88..cf137699 100644
--- a/lib.c
+++ b/lib.c
@@ -1440,6 +1440,28 @@ val iter_reset(val iter, val obj)
}
}
+val iterp(val obj)
+{
+ switch (type(obj)) {
+ case NIL:
+ case CHR:
+ case NUM:
+ case BGNUM:
+ case FLNUM:
+ case CONS:
+ case LCONS:
+ return t;
+ case COBJ:
+ if (obj->co.cls == seq_iter_cls)
+ return t;
+ if (obj_struct_p(obj) && get_special_slot(obj, iter_step_m))
+ return t;
+ /* fallthrough */
+ default:
+ return nil;
+ }
+}
+
val iter_catv(varg iters)
{
cnum index = 0;