Created
November 13, 2010 20:30
-
-
Save antoniogarrote/675614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Example from 'Applicative Programming with Effects' by McBride & Paterson | |
(use 'clj-control.applicative) | |
(use 'clj-control.core) | |
(use 'clj-control.utils) | |
(defn transpose | |
([matrix] | |
(if (empty? matrix) | |
(repeat '()) | |
(let [xs (first matrix) | |
xss (rest matrix)] | |
(af-* | |
(af-* (repeat (count xs) (curry 2 cons)) xs) | |
(take (count xs) (transpose xss))))))) | |
(def *res* (transpose '((1 2 3) (4 5 6) (7 8 9)))) | |
(doseq [r *res*] | |
(print "[") | |
(doseq [c r] | |
(print (str " " c) )) | |
(println " ]")) | |
;; [ 1 4 7 ] | |
;; [ 2 5 8 ] | |
;; [ 3 6 9 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment