diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-06-26 06:56:10 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-06-26 06:56:10 -0700 |
commit | 3dbaecd359c584e1bcf650cdf53fb35253599e15 (patch) | |
tree | cdabf8284e140a72cd19e447bfab7ec7bde94f85 /txr.1 | |
parent | 5b0ee1a4dcdad30c4554a9aaa17600ae3e8073d7 (diff) | |
download | txr-3dbaecd359c584e1bcf650cdf53fb35253599e15.tar.gz txr-3dbaecd359c584e1bcf650cdf53fb35253599e15.tar.bz2 txr-3dbaecd359c584e1bcf650cdf53fb35253599e15.zip |
* eval.c (mapcarv): Use mapcar_listout, so list_of_lists can be
a non-list sequence.
(eval_init): Register transpose and zip as intrinsics.
* lib.c (curry_12_1_v): New static function.
(transpose, mapcar_listout): New functions.
(mapcar): Redefined in terms of mapcar_listout.
* lib.h (transpose, mapcar_listout): Declared.
* txr.1: Documented transpose and zip.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -8056,6 +8056,57 @@ Examples: (mappend (lambda (item) (if (evenp x) (list x))) '(1 2 3 4 5)) -> (2 4) +.SS Functions tranpose and zip + +.TP +Syntax: + + (transpose <sequence>) + (zip <sequence>*) + +.TP +Description: + +The transpose function performs a transposition on <sequence>. This means that the +elements of <sequence> must be sequences. These sequences 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 +<sequence>, 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 <sequence>) must have elements +which are compatible with the first sequence. This means that if the first +element of <sequence> is a string, then the remaining sequences must be +strings, or else sequences of characters, or of strings. + +The zip function takes variable arguments, and is equivalent to calling +transpose on a list of the arguments. The following equivalences hold: + + (zip . x) <--> (transpose x) + + [apply zip x] <--> (transpose x) + +.TP +Examples: + + ;; transpose list of lists + (transpose '((a b c) (c d e))) -> ((a c) (b d) (c e)) + + ;; transpose vector of strings: + ;; - string columns become string rows + ;; - vector input becomes vector output + (transpose #("abc" "def" "ghij")) -> #("adg" "beh" "cfi") + + ;; error: transpose wants to make a list of strings + ;; but 1 is not a character + (transpose #("abc" "def" '(1 2 3))) ;; error! + + ;; String elements are catenated: + (transpose #("abc" "def" ("UV" "XY" "WZ"))) -> #("adUV" "beXY" "cfWZ") + + (zip '(a b c) '(c d e)) -> ((a c) (b d) (c e)) + .SS Functions conses and conses* .TP |