我想转置列表的列表;我的评论表明了思维过程。在Common Lisp中转置列表
(setq thingie '((1 2 3) (4 5 6) (7 8 9))) ;;test case
(defun trans (mat)
(if (car mat)
(let ((top (mapcar 'car mat)) ;;slice the first row off as a list
(bottom (mapcar 'cdr mat))) ;;take the rest of the rows
(cons top (trans bottom)))) ;;cons the first-row-list with the next-row-list
mat)
(trans thingie)
=> ((1 2 3) (4 5 6) (7 8 9)) ;;wait what?
但是,我真的希望它是
((1 4 7) (2 5 8) (3 6 9))
我在做什么错?
这被称为[矩阵转置](http://en.wikipedia.org/wiki/Transpose)。 – sds 2013-08-27 18:43:52
@sds:... yuuup。为什么我3年前没有看到超越我。给我几分钟,我会解决这个问题。 – 2013-08-27 22:38:33