55502f40dc8b7c769880b10874abc9d0

simpler? shorter?

(defun transpose (m)
       (cond
        ((null (car m)) nil)
        (T (cons (mapcar 'car m) (transpose (mapcar 'cdr m))))
       ))

(transpose '((1 2 3) (4 5 6) (7 8 9)))

Refactorings

No refactoring yet !

14d99459914c594998d2506db1e868c2

Kartik Agaram

October 3, 2007, October 03, 2007 12:55, permalink

No rating. Login to rate!

Nice! Totally beats what I had before.

F2c50bde11723bbb26ac7aa17ee9a0ad

mdengler

October 6, 2007, October 06, 2007 04:31, permalink

No rating. Login to rate!

Style, and also didn't you want #'car, rather than 'car?

(defun transpose (m)
  (unless (null (car m))
    (cons (mapcar #'car m) (transpose (mapcar #'cdr m)))))

(transpose '((1 2 3) (4 5 6) (7 8 9)))
Ca569f6c87196fd0a204719c7885370f

acjr

November 8, 2007, November 08, 2007 12:01, permalink

No rating. Login to rate!

If the "Cond" returns a value, try this:

(defun Transpose (m) (Cond ((CAR m) (Cons (MapCAR 'CAR m) (Transpose (MapCAR 'CDR m))))))
D41d8cd98f00b204e9800998ecf8427e

anonymous

May 23, 2008, May 23, 2008 19:17, permalink

1 rating. Login to rate!
(defun transpose (m)
  (apply #'mapcar #'list m))
E9558f012a4568bcce3555bbe5573e00

confused?

May 23, 2008, May 23, 2008 21:58, permalink

No rating. Login to rate!

that's great! how did you do that!!

Your refactoring





Format Copy from initial code

or Cancel