From 07e40c025d65beeced5ac83485eb13dab9b7d2ae Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 7 Mar 2025 00:11:37 -0800 Subject: 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. --- lib.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib.c') 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; -- cgit v1.2.3