Using Clojure for Scripting
Posted by Uncle Bob on 08/08/2009
Clojure makes a nice language for writing scripts that explore things on the filesystem. For example, here is a cute little program that explores the FitNesse source tree counting the lines of production java code and comparing it to the lines of unit test code.
(use 'clojure.contrib.duck-streams) (def file-counts (map #(list (.toString %) (count (read-lines %))) (remove #(.isDirectory %) (file-seq (file-str "~/projects/FitNesseGit/src/fitnesse"))))) (defn count-lines-that-end-with [file-counts suffix] (reduce + (map second (filter #(.endsWith (first %) suffix) file-counts)))) (def java-count (count-lines-that-end-with file-counts ".java")) (def test-count (count-lines-that-end-with file-counts "Test.java")) (printf "Java lines: %d\n" java-count) (printf "Test lines: %d\n" test-count) (printf "Test pct: %.1f\n" (double (* 100 (/ test-count java-count))))
Comments
Luis Sergio Oliveira 5 days later:
I started a while ago exploring this in Common Lisp (with Franz’s Allegro CL implementation). My objective is to automate administrative and information extraction tasks. So far it is powerful enough, having interfaces with the shell, Operating System as with M$ Office (COM), being the main problem the lack of high level structure of the data, mainly if it is document oriented.
han 8 months later:
http://www.ipadvideoconverters.biz iPad Video Converter iPad Video Converter is a great software for iPad lovers to convert videos to iPad with super fast speed and high quality. Its easy-to-use interface makes iPad to videos conversion routine very simple. And also it can keep the original quality of video files.
taylor lautner 11 months later:
interesting “cute” little program. I’m a beginner scripter, using a couple languages, Java, Python, Mel Script, and Apple Script, but I haven’t tried out Clojure.