diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-01-19 19:01:21 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-01-19 19:01:21 -0800 |
commit | 2f0031c8f8efb9fb76692442f85d47f61cc9b059 (patch) | |
tree | c96da51a2d0873ca9407d129b4a54f47b1498b39 /lib.h | |
parent | fbf3ae2f5c6c89c3d48ffe40760b9f31d7dfbadd (diff) | |
download | txr-2f0031c8f8efb9fb76692442f85d47f61cc9b059.tar.gz txr-2f0031c8f8efb9fb76692442f85d47f61cc9b059.tar.bz2 txr-2f0031c8f8efb9fb76692442f85d47f61cc9b059.zip |
We need a length-< special method.
Structure objects can be used to implement lazy structures
such as sequences. It is undesirable to take the length of
a lazy sequence because it forces all of its elements to
exist. Moreover, if the sequence is infinite, it is
impossible. There are situations in which it is only necessary
to know whether the length is less than a certain bound,
and for that we have the length-< function. That works on
infinite sequence such as lazy lists, requiring them to be
forced only so far as to determine the truth value of the
test. We need objects that implement lazy sequences to work
with this function.
* struct.h (enum special_slot): New member length_lt_m.
* lib.h (length_lt_s): Symbol variable declared.
* struct.c (special_sym): New entry in this table, associating
the length_lt_m enum with the length_lt_s symbol variable.
* lib.c (length_lt_s): Symbol variable defined.
(length_lt): Handle COBJ objects that are structures.
we test whether they have a length-< method, or else length
method. If they don't have either, we throw. We don't
fall back on the default case for objects that don't have
a length-< method, because the diagnostic won't be good
if they don't have a length method either; the programmer
will be informed that the length function couldn't find
a length method, without mentioning that it was actually
length-< that is being used.
* eval.c (eval_init): Register length-< using the length_lt_s
symbol variable rather than using intern.
* txr.1: Documented.
* tests/012/oop-seq.tl: New tests.
Diffstat (limited to 'lib.h')
-rw-r--r-- | lib.h | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -692,7 +692,7 @@ extern val query_error_s, file_error_s, process_error_s, syntax_error_s; extern val timeout_error_s, system_error_s, alloc_error_s, stack_overflow_s; extern val path_not_found_s, path_exists_s, path_permission_s; extern val warning_s, defr_warning_s, restart_s, continue_s; -extern val gensym_counter_s, length_s; +extern val gensym_counter_s, length_s, length_lt_s; extern val rplaca_s, rplacd_s, seq_iter_s; extern val lazy_streams_s; extern val plus_s; |