t3x.org / nss / transpose.html

(Nils' Scheme Snippets)

 
Paren matching: ON  |  Category: math  |  Overview  |  Scheme Books  |  License
 

(transpose list) => list

 
Purpose
Transpose a matrix. A matrix is represented using a nested list, where each inner list is a column of the matrix.
 
Arguments
x matrix
 
Example
(transpose '((1 2 3) (4 5 6))) => ((1 4) (2 5) (3 6))
(define (transpose x)
  (apply map list x))

Copyright (C) 2007 Nils M Holm <nmh @ t3x . org>