summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-07-24 20:59:56 -0700
committerKaz Kylheku <kaz@kylheku.com>2024-07-24 20:59:56 -0700
commit0de738cf7b535f70eeaf3b5452ed8a705cb03655 (patch)
treea9c97f400bf6b43825ef0b4f6a6cc941e4aec887 /txr.1
parent96e0815b2838becd739d471c5e0edb7e3dac46fc (diff)
downloadtxr-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 'txr.1')
-rw-r--r--txr.133
1 files changed, 20 insertions, 13 deletions
diff --git a/txr.1 b/txr.1
index a92a484a..b2acfb14 100644
--- a/txr.1
+++ b/txr.1
@@ -38388,19 +38388,10 @@ elements of
must be iterable. These iterables are understood to be
columns; transpose exchanges rows and columns, returning a sequence of the rows
which make up the columns. The returned sequence is of the same kind as
-.metn iterable ,
-and the rows are also the same kind of sequence as the first column
-of the original sequence. The number of rows returned is limited by the
-shortest column among the sequences.
-
-All of the input sequences (the elements of
-.metn iterable )
-must have elements
-which are compatible with the first sequence. This means that if the first
-element of
-.meta iterable
-is a string, then the remaining sequences must be
-strings, or else sequences of characters, or of strings.
+.metn iterable .
+The rows are also the same kind of sequence as the first element
+of the original sequence, if possible, otherwise they are lists. The number of
+rows returned is limited by the shortest column among the sequences.
The
.code zip
@@ -38414,6 +38405,22 @@ on a list of the arguments. The following equivalences hold:
[apply zip x] <--> (transpose x)
.brev
+A special requirement applies when the first argument of
+.code zip
+or the first element of the
+.meta iterable
+argument of
+.code transpose
+is a string. In this situation, the tuples which emerge are strings,
+if possible. The special requirement is that column elements which are
+strings are treated as individual items and appended to the row strings.
+For example,
+.code "(zip \(dqab\(dq #(\(dqrst\(dq \(dqxyz\(dq))"
+produces
+.codn "(\(dqarst\(dq \(dqbxyz\(dq)" ,
+rather than
+.codn "((\(dqa\(dq \(dqrst\(dq) (\(dqb\(dq \(dqxyz\(dq))" .
+
.TP* Examples:
.verb
;; transpose list of lists