Matrix transposition: Difference between revisions
Content added Content deleted
m (→{{header|J}}: add solution/example headings) |
(added Clojure) |
||
Line 275: | Line 275: | ||
After execution, the memory maps of a and b will be those of m by n arrays instead |
After execution, the memory maps of a and b will be those of m by n arrays instead |
||
of n by m. |
of n by m. |
||
=={{header|Clojure}}== |
|||
{{trans|Common Lisp}} |
|||
<lang lisp>;takes matrix represented as nested lists |
|||
(defn transpose [m] |
|||
(apply map list m)) |
|||
;takes matrix represented as nested vectors |
|||
(defn transpose [m] |
|||
(vec (apply map vector m)))</lang> |
|||
<lang lisp>; takes both representations (and can be extended) |
|||
(defmulti transpose class) |
|||
(defmethod transpose clojure.lang.PersistentList [m] |
|||
(apply map list m)) |
|||
(defmethod transpose clojure.lang.PersistentVector [m] |
|||
(vec (apply map vector m))) |
|||
</lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |