Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; 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 ]
Add Comment
Please, Sign In to add comment