[slime-devel] transpose-lists

Edi Weitz edi at agharta.de
Tue Aug 9 14:00:23 UTC 2005


Hi!

I've just committed a new implementation of TRANSPOSE-LISTS (see
below) because the old one (although it was cute) had problems with
CALL-ARGUMENTS-LIMIT.  Light testing reveals no problems with the
Lisps I have on my hard drive but maybe some LOOP black belt detects a
violation of the spec that I don't see.

Cheers,
Edi.



(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))))



More information about the slime-devel mailing list