summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-03-06 21:42:50 -0800
committerKaz Kylheku <kaz@kylheku.com>2025-03-06 21:42:50 -0800
commita68a67376127cb9accf26c4ed43438f188eb24c8 (patch)
tree5afc06409f0afdca8dbf162519e5ee2bd4bbf195 /lib.h
parent862677be200fce120af136a392a780eb4816fa64 (diff)
downloadtxr-a68a67376127cb9accf26c4ed43438f188eb24c8.tar.gz
txr-a68a67376127cb9accf26c4ed43438f188eb24c8.tar.bz2
txr-a68a67376127cb9accf26c4ed43438f188eb24c8.zip
iterator API: reject objects that don't make sense.
* lib.c (iter_more): Do not return t for unrecognized objects, but thrown an exception. Do return t for conses, which is necessary since they are iterators for lists. Also, as a special case, we return t for struct objects that don't have an iter-more method. This is needed for the documented fast protocol. Iterator objects implementing the fast protocol still get iter-more invoked on them. The client usually doesn't know that the iterator implements the fast protocol, and so calls iter-more, which unconditionally has to returns true. (iter_item): Do not fall back on car(iter) for all unhandled objects. Only conses are handled via car. All unrecognized objects trigger an exception. (iter_step): Do not try to handle list-like objects via cdr, only lists. Improve the diagnostic for hitting the end of an improper list: diagnostic shows the cons cell rather than just the terminating atom. * tests/012/iter.tl: Some test cases validating that the functions error out for strings and vectors. Much more coverage is possible here but doesn't seem worth it; e.g. that the functions reject a buffer, regex, function, ...
Diffstat (limited to 'lib.h')
0 files changed, 0 insertions, 0 deletions