[slime-devel] transpose-lists
Helmut at common-lisp.net
Helmut at common-lisp.net
Tue Aug 9 15:18:52 UTC 2005
* Edi Weitz [2005-08-09 16:00+0200] writes:
> (defun transpose-lists (lists)
> "Turn a list-of-lists on its side.
> If the rows are of unequal length, truncate uniformly to the shortest.
>
> For example:
> \(transpose-lists '((ONE TWO THREE) (1 2)))
> => ((ONE 1) (TWO 2))"
> (catch 'done
> (loop with result
> with collectors = (loop for list in lists
> collect (let ((list list))
> (lambda ()
> (cond ((null list)
> (throw 'done result))
> (t (pop list))))))
> collect (loop for collector in collectors
> collect (funcall collector)) into temp-result
> do (setq result temp-result))))
Uugh, how ugly :-)
How about?
(defun transpose-lists (lists)
(cond ((some #'null lists) '())
(t (cons (mapcar #'car lists)
(transpose-lists (mapcar #'cdr lists))))))
More information about the slime-devel
mailing list