Guest User

Untitled

a guest
Jun 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. ;;; Example from 'Applicative Programming with Effects' by McBride & Paterson
  2.  
  3. (use 'clj-control.applicative)
  4. (use 'clj-control.core)
  5. (use 'clj-control.utils)
  6.  
  7. (defn transpose
  8. ([matrix]
  9. (if (empty? matrix)
  10. (repeat '())
  11. (let [xs (first matrix)
  12. xss (rest matrix)]
  13. (af-*
  14. (af-* (repeat (count xs) (curry 2 cons)) xs)
  15. (take (count xs) (transpose xss)))))))
  16.  
  17. (def *res* (transpose '((1 2 3) (4 5 6) (7 8 9))))
  18.  
  19. (doseq [r *res*]
  20. (print "[")
  21. (doseq [c r]
  22. (print (str " " c) ))
  23. (println " ]"))
  24.  
  25. ;; [ 1 4 7 ]
  26. ;; [ 2 5 8 ]
  27. ;; [ 3 6 9 ]
Add Comment
Please, Sign In to add comment