Subject: code for the transpose of a list of lists.
From: Pedro Garrido gomez
Date: Mon, 28 Jun 2010 22:22:49 +0000 (GMT)
This is the code for a version of transpose, this one is destructive, so
perhaps should be called transpose!.
?
?This version is about
seven time faster than the version in maxima list.
?Yours
sincerely, Pero Garrido
?
?? (defun transpose(m)
? (let (m1)
???
(setq m1 (loop for x on (car m) collect x))
??? (transposeaux m)
???
m1))
??? ??? ?
(defun transposeaux(ll)
? (let (next)
???
(loop for l1 in ll
?????? for l2
in (cdr ll) do
??? ?? (loop for ai = l1 then next
??? ????? for
bi on l2 do
??? ??? (setf next (cdr
ai))
??? ??? (rplacd ai bi))
??? ?finally
??? ?? (loop for bi
= l2 then next
??? ??? while (cdr bi) do
??? ??? (setf next (cdr
bi)
??? ??? ????? (cdr bi) nil)))??? ????
??? ll))
(defmacro
tra(m)
? `(setq ,m (transpose ,m)))