Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. (require '[clojure.reflect]
  2. '[clojure.java.io :as io])
  3.  
  4. (->> (clojure.reflect/reflect java.nio.file.Paths)
  5. :members)
  6. #_#{{:name java.nio.file.Paths,
  7. :declaring-class java.nio.file.Paths,
  8. :parameter-types [],
  9. :exception-types [],
  10. :flags #{:private}}
  11. {:name get,
  12. :return-type java.nio.file.Path,
  13. :declaring-class java.nio.file.Paths,
  14. :parameter-types [java.lang.String java.lang.String<>],
  15. :exception-types [],
  16. :flags #{:varargs :public :static}}
  17. {:name get,
  18. :return-type java.nio.file.Path,
  19. :declaring-class java.nio.file.Paths,
  20. :parameter-types [java.net.URI],
  21. :exception-types [],
  22. :flags #{:public :static}}}
  23. (java.nio.file.Paths/get "/usr" (into-array String ["bin" "perl"]))
  24. (java.nio.file.Paths/get (java.net.URI. "file:///usr/bin/perl"))
  25.  
  26.  
  27. ;;; mv, mkdir, cp とか 基本的な Unix コマンドに対応する様なものがある
  28. ;;; そうじゃないものあるけど
  29. ;;; 引数は基本的に java.nio.file.Path
  30. (->> (clojure.reflect/reflect java.nio.file.Files)
  31. :members
  32. (remove #((:flags %) :private))
  33. (remove :type) ;remove variables
  34. ;; (filter #(= 'java.nio.file.Path (-> % :parameter-types first)))
  35. #_(filter #(and (= 'java.nio.file.Path (get-in % [:parameter-types 0]))
  36. (= 'java.nio.file.Path (get-in % [:parameter-types 1]))))
  37. ;; (map :name)
  38. ;; distinct
  39. ;; sort
  40. )
  41.  
  42.  
  43. ;;; 出来なかった
  44. (comment
  45. (java.nio.file.Files/walkFileTree
  46. (java.nio.file.Paths/get "/etc" (into-array String []))
  47. (fn [p a]))
  48.  
  49. (with-open [r (io/reader "/etc/passwd")]
  50. (-> r
  51. .lines
  52. (.forEach println)))
  53.  
  54. (with-open [r (io/reader "/etc/passwd")]
  55. (-> r
  56. .lines
  57. (.forEach System.out.p)))
  58. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement