【发布时间】:2011-03-31 14:22:41
【问题描述】:
我正在尝试转置列表列表;我的 cmets 表明了思考的过程。
(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))
我做错了什么?
【问题讨论】:
-
@sds: ... yuuup。为什么我三年前没有看到这一点超出了我的范围。给我几分钟,我会解决这个问题。
标签: lisp common-lisp