; http://cap-lore.com/code/Scheme/transpose.html
(lambda (zer zer?) (lambda (x) (let trn ((x x))
(if (null? x) '() (let ((z (trn (cdr x)))
(b (lambda (x y) (if (and (null? y) (zer? x)) '() (cons x y)))))
(let m ((u (car x))(z z))
(if (null? u) (map (lambda (q) (if (null? q) '() (cons zer q))) z)
(if (null? z) (let y ((q u)) (if (null? q) '() (let ((p (y (cdr q))))
(if (and (null? p) (zer? (car q))) '()
(cons (if (zer? (car q)) '() (list (car q))) p)))))
(cons (b (car u)(car z)) (m (cdr u)(cdr z)))))))))))
; tests
(define tr0 ((fileVal "transpose0") 0 zero?))
(tr0 '((0 0 0 0 0 1) () (0 0) (0 1 0))) ; => (() (0 0 0 1) () () () (1))
(tr0 '((0 0) (0 1 0))) ; => (() (0 1))