diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-07-24 20:59:56 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-07-24 20:59:56 -0700 |
commit | 0de738cf7b535f70eeaf3b5452ed8a705cb03655 (patch) | |
tree | a9c97f400bf6b43825ef0b4f6a6cc941e4aec887 /tests | |
parent | 96e0815b2838becd739d471c5e0edb7e3dac46fc (diff) | |
download | txr-0de738cf7b535f70eeaf3b5452ed8a705cb03655.tar.gz txr-0de738cf7b535f70eeaf3b5452ed8a705cb03655.tar.bz2 txr-0de738cf7b535f70eeaf3b5452ed8a705cb03655.zip |
zip: more permissive implementation.
zip and transpose should allow non-character data
when the leftmost column is a string, falling back
on making lists, like seq_build.
We can't use seq_build as-is because of the special
semantics of transpose/zip with regard to strings.
We introduce a "strcat" variant of seq_build
for this purpose.
* lib.c (seq_build_strcat_add): New static function.
(sb_strcat_ops): New static structure like sb_str_ops,
but with seq_build_strcat_add as the add operation,
which allows string arguments to be appended to the
string rather than switching to a list.
(seq_build_strcat_init): New function.
* lib.h (seq_build_strcat_init): Declared.
* eval.c (zip_strcat): New static function; uses
seq_build_strcat_init.
(zipv): Only recognize strings specially; all else goes
through the existing default case.
Strings use zip_strcat.
* tests/012/seq.tl: New test case.
* txr.1: Describe special semantics of zip/tranpose;
previously only documented in one example.
Clarify that the rows are only sequences of the
same kind as the leftmost column if possible,
otherwise lists. Remove text which says that it's an error
for the other columns to contain non-string, non-character
objects if the leftmost column is a string.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/012/seq.tl | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/012/seq.tl b/tests/012/seq.tl index 29fea518..148f1899 100644 --- a/tests/012/seq.tl +++ b/tests/012/seq.tl @@ -844,6 +844,9 @@ (test (zip "ab" '(#\i #\j) #("x" "y")) ("aix" "bjy")) +(test + (zip "abc" '(#\a 2 3)) ("aa" (#\b 2) (#\c 3))) + (vtest [apply mapcar join (list-seq "aaa".."zzz")] (transpose (list-seq "aaa".."zzz"))) |