Skip to content

Instantly share code, notes, and snippets.

@antoniogarrote
Created November 13, 2010 20:30
Show Gist options
  • Save antoniogarrote/675614 to your computer and use it in GitHub Desktop.
Save antoniogarrote/675614 to your computer and use it in GitHub Desktop.
;;; 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