Skip to content

Instantly share code, notes, and snippets.

@jeffcarp

jeffcarp/kata13.clj

Created Dec 19, 2013
Embed
What would you like to do?
(use 'clojure.java.io)
(defn debug [expr str]
(do
(println str expr)
(identity expr)))
(defn basic-comment? [str]
(not (empty? (re-seq #"^\s*\/\/" str))))
(defn starts-comment? [str]
(not (empty? (re-seq #"\/\*" str))))
(defn ends-comment? [str]
(not (empty? (re-seq #"\*\/" str))))
(defn block-comment? [is-comment str]
(and (not (ends-comment? str))) (or is-comment (starts-comment? str)))
(defn foo [num-lines raw-lines is-comment]
(let [line (first raw-lines)]
(if (empty? raw-lines)
num-lines
(if (every? not ((juxt clojure.string/blank? basic-comment? (partial block-comment? is-comment)) line))
(foo (inc num-lines) (rest raw-lines) (debug (block-comment? is-comment line) "block-comment? line"))
(foo num-lines (rest raw-lines) (debug (block-comment? is-comment line) "block-comment? line"))))))
(with-open [rdr (reader "test1.txt")]
(foo 0 (line-seq rdr) false))
;(count (filter
; #(not (or (clojure.string/blank? %) (basic-comment? %)))
; (line-seq rdr))))
; "/\\*(?:.|[\\n\\r])*?\\*/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.