Counting lines in a file
(ns tokenize
(:import (java.io BufferedReader FileReader)))
(ns tokenize
(:import (java.io BufferedReader FileReader)))
;# This is a comment?
(defn process-file [file-name line-function counter]
(println " starting from imperative "
(with-open [rdr (BufferedReader. (FileReader. file-name))]
(reduce line-function counter (line-seq rdr) ))))
(defn process-file [file-name line-function counter]
(println " starting from imperative "
(with-open [rdr (BufferedReader. (FileReader. file-name))]
(reduce line-function counter (line-seq rdr) ))))
(defn process-line [acc line]
(+ acc 1))
(+ acc 1))
(process-file "../../<filepath>" process-line 0)
Simple sum
(defn mysum [base arg1]
(+ base arg1))
(println " works "(mysum (mysum 1 2) 4))
(time (dotimes [i 5] (println "woha!")))
(time (dotimes [i 5] (println "woha!")))
line counting shorter
(ns tokenize
(:import (java.io BufferedReader FileReader)))
(defn process-file [file-name]
(with-open [rdr (BufferedReader. (FileReader. file-name))]
(doseq [line (line-seq rdr)] (println line))))
(process-file "<filepath>")
Hello Clojure
(println "Hello, world!" (.. System (getProperties) (get "os.name")))
Since Clojure is a functional language and don't offer imperative constructs like loops it takes a bit to get used to but it is definitely worth a first look. Evaluation concerning how it works out, building bigger systems and what performance issue possibly arise is of course a matter of further investigaion.