stringsSo do you mean you've got the lists like this:
_$ (setq lst
(list
(list a1 a2 a3 a4 a5)
(list b1 b2 b3 b4 b5)
(list c1 c2 c3 c4 c5)
(list d1 d2 d3 d4 d5)
)
)
((nil nil nil nil nil) (nil nil nil nil nil) (nil nil nil nil nil) (nil nil nil nil nil))
_$ (setq lst (list
(list "a1" "a2" "a3" "a4" "a5")
(list "b1" "b2" "b3" "b4" "b5")
(list "c1" "c2" "c3" "c4" "c5")
(list "d1" "d2" "d3" "d4" "d5")))
(("a1" "a2" "a3" "a4" "a5") ("b1" "b2" "b3" "b4" "b5") ("c1" "c2" "c3" "c4" "c5") ("d1" "d2" "d3" "d4" "d5"))
_$ (transpose-matrix lst)
(("a1" "b1" "c1" "d1") ("a2" "b2" "c2" "d2") ("a3" "b3" "c3" "d3") ("a4" "b4" "c4" "d4") ("a5" "b5" "c5" "d5"))
(("a1" "b1" "c1" "d1") ("a2" "b2" "c2" "d2") ("a3" "b3" "c3" "d3") ("a4" "b4" "c4" "d4") ("a5" "b5" "c5" "d5"))
If strings, then as per Kerry's answer: Matrix Transpose (http://en.wikipedia.org/wiki/Transpose).
The oldest sample of a Transpose function I can find is this (1996): http://autocad.xarch.at/lisp/transpose.002.html
It works very well:Code - Auto/Visual Lisp: [Select]
I'm rusty irne, forgot all about that gem.Yes, I forgot about it until a few years ago when I saw it again!
I'm rusty irne, forgot all about that gem.Yes, I forgot about it until a few years ago when I saw it again!
At first it seems to be "magic" ... but if you work out what it does, you realize this is probably the most awesome sample of functional programming!
1+Strange, I tried looking for similar code in other languages (even other functional stuff) but it seems Lisp simply lends itself to this function.
Strange, I tried looking for similar code in other languages (even other functional stuff) but it seems Lisp simply lends itself to this function.
Using a linked list as with LISP:Not sure, I'm no F# boffin ... but is this tail-recursively optimized (http://en.wikibooks.org/wiki/F_Sharp_Programming/Recursion#Tail_Recursion)?Code - F#: [Select]